fix: detect email-based MFA in widget SSO login#371
Conversation
The widget+cffi login strategy only recognized an MFA challenge when the returned page <title> contained the literal substring "MFA", which matches the authenticator-app (TOTP) page "Enter MFA code for login". Email-based one-time-code MFA instead returns a page titled "GARMIN Authentication Application", so login fell through to the generic "unexpected title" error and never prompted for the code. Garmin permanently enforces MFA on ECG-capable devices (e.g. Venu 4, Fenix 8) and email is a common method there, so affected accounts could not authenticate at all via the widget flow. Broaden the detection to also match the email-MFA title. No completion change is needed — both variants are already verified through the same /sso/verifyMFA/loginEnterMfaCode endpoint. Verified end-to-end against a live email-MFA account. Adds in-process tests covering both MFA title variants and a negative case ensuring unrelated titles still raise the unexpected-title error. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
WalkthroughThis PR refines widget SSO login MFA detection to recognize both authenticator-app and email one-time-code page title variants with case-insensitive matching, replacing a narrow substring check. It includes a new test module that validates both positive (MFA detection) and negative (unexpected title rejection) behaviors using a fully mocked session. ChangesWidget MFA Detection
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Are you 100% sure? I tested each and every strategy with MFA in latest version, I even wrote a script to do it. Its in the package. |
|
And I have only email based MFA enabled, never used app. |
|
Hey @cyberjunky I have fenix 8 with ECG recordings and Garmin forced me to use MFA (email was default). I ran into this exact issue Taxuspt/garmin_mcp#109 and the fix in this branch got me authenticated successfully. Let me know if you need more details |
… bump 0.3.6 Follow-up to PR #371 (email-MFA detection in the widget flow): - add tests for _complete_mfa_widget — the completion step that actually logs an email-/TOTP-MFA user in (success ticket exchange, missing context, rejected/expired code). PR #371 covered detection only. - add test_widget_mfa to the [[tool.mypy.overrides]] allowlist so `mypy garminconnect tests` (local lint) stays green; CI was unaffected (it only type-checks garminconnect/). - bump version to 0.3.6.
Problem
The
widget+cffilogin strategy only treats the post-login page as an MFA challenge when its HTML<title>contains the literal substring"MFA":That works for authenticator-app (TOTP) MFA, whose page is titled
Enter MFA code for login. But email-based one-time-code MFA returns a page titledGARMIN Authentication Application, which contains no"MFA". Login therefore falls through to the genericWidget login: unexpected title '...'error and the user is never prompted for the emailed code.Garmin permanently enforces MFA on ECG-capable devices (e.g. Venu 4, Fenix 8), where email is a common method — so affected accounts can't authenticate via the widget flow at all. This is the same symptom previously reported for the old garth flow in #242.
Fix
Broaden the MFA detection in
_widget_web_loginto recognize the email-MFA title as well, reusing the already-computedtitle_lower:No change is needed to MFA completion: both variants are already verified through the same
/sso/verifyMFA/loginEnterMfaCodeendpoint in_complete_mfa_widget.Verification
login()now prompts for the emailed code and authenticates successfully.unexpected titleerror.test_widget_mfa,test_login_recovery,test_garmin_unit,test_retry_decorator→ 101 passed);ruff check garminconnect/client.pyclean.Scope
One-line detection change plus tests. No behavioral change for TOTP MFA, successful logins, or the credential/error paths (the negative test guards against over-broad matching).
Summary by CodeRabbit
Release Notes