Add MFA/2FA support for Garmin Connect setup - #4
Open
Andrejchrcek wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
scripts/sync_garmin.py
MFA support — added get_mfa() callback passed as prompt_mfa=get_mfa to the Garmin() constructor. The callback is only invoked when Garmin requires a code; accounts without 2FA are unaffected.
Version pin — changed garminconnect>=0.2.38 to garminconnect==0.2.38. Version 0.3.x was recently released and removed the garth-based OAuth entirely, breaking the script. Pinning to the last 0.2.x release keeps the existing auth flow stable.
Smarter "no profile" handling — removed the retry loop in setup(). The old loop re-triggered client.login() on failure, which re-prompted for an MFA code that was already expired. Now, when a "no profile" error occurs after a successful OAuth flow (Cloudflare blocking the profile check, not the login itself), the script saves the tokens anyway and warns the user instead of failing.
Removed misleading error message — the old 401 error handler told users to disable 2FA; that text is removed since 2FA is now supported.
README.md
Removed "two-factor authentication must be disabled" from requirements
Updated the 2FA troubleshooting section to document MFA usage instead of instructing users to disable it
Updated Auth notes section accordingly
Testing
Tested against an account with 2FA enabled. Setup flow:
Garmin Connect password:
Enter MFA/OTP code from your authenticator app: xxxxxx
Warning: Garmin's profile endpoint was temporarily unavailable,
but your OAuth tokens were saved to /root/.garminconnect.
Run the sync to verify everything works.
Subsequent uv run scripts/sync_garmin.py uses cached tokens with no credentials or MFA required.