Skip to content

Add MFA/2FA support for Garmin Connect setup - #4

Open
Andrejchrcek wants to merge 2 commits into
freakyflow:mainfrom
Andrejchrcek:main
Open

Add MFA/2FA support for Garmin Connect setup#4
Andrejchrcek wants to merge 2 commits into
freakyflow:mainfrom
Andrejchrcek:main

Conversation

@Andrejchrcek

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant