Skip to content

Commit

Permalink
Added support for MFA
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberjunky committed Apr 25, 2024
1 parent 6aeeb3c commit 6113718
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def display_json(api_call, output):

print(footer)


def display_text(output):
"""Format API output for better readability."""

Expand Down Expand Up @@ -207,7 +208,7 @@ def init_api(email, password):
if not email or not password:
email, password = get_credentials()

garmin = Garmin(email, password)
garmin = Garmin(email=email, password=password, is_cn=False, prompt_mfa=get_mfa)
garmin.login()
# Save Oauth1 and Oauth2 token files to directory for next login
garmin.garth.dump(tokenstore)
Expand All @@ -229,6 +230,12 @@ def init_api(email, password):
return garmin


def get_mfa():
"""Get MFA."""

return input("MFA one-time code: ")


def print_menu():
"""Print examples menu."""
for key in menu_options.keys():
Expand Down
9 changes: 7 additions & 2 deletions garminconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
class Garmin:
"""Class for fetching data from Garmin Connect."""

def __init__(self, email=None, password=None, is_cn=False):
def __init__(
self, email=None, password=None, is_cn=False, prompt_mfa=None
):
"""Create a new class instance."""
self.username = email
self.password = password
self.is_cn = is_cn
self.prompt_mfa = prompt_mfa

self.garmin_connect_user_settings_url = (
"/userprofile-service/userprofile/user-settings"
Expand Down Expand Up @@ -198,7 +201,9 @@ def login(self, /, tokenstore: Optional[str] = None):
else:
self.garth.load(tokenstore)
else:
self.garth.login(self.username, self.password)
self.garth.login(
self.username, self.password, prompt_mfa=self.prompt_mfa
)

self.display_name = self.garth.profile["displayName"]
self.full_name = self.garth.profile["fullName"]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "garminconnect"
version = "0.2.16"
version = "0.2.17"
description = "Python 3 API wrapper for Garmin Connect"
authors = [
{name = "Ron Klinkien", email = "ron@cyberjunky.nl"},
Expand Down

0 comments on commit 6113718

Please sign in to comment.