Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support for Garmin MFA (Two-Factor Auth) #410

Closed
philosowaffle opened this issue Jan 5, 2023 · 5 comments · Fixed by #432
Closed

[Feature] Support for Garmin MFA (Two-Factor Auth) #410

philosowaffle opened this issue Jan 5, 2023 · 5 comments · Fixed by #432
Assignees
Labels
enhancement new feature / improvments WIP
Milestone

Comments

@philosowaffle
Copy link
Owner

Garmin supports MFA/2FA. See if there is any way that P2G can work with Garmin accounts that have MFA/2FA enabled.

#408

@philosowaffle philosowaffle added the research needed needs more research by developer label Jan 5, 2023
@philosowaffle philosowaffle added the enhancement new feature / improvments label Jan 14, 2023
@philosowaffle philosowaffle changed the title Research: Options for handling Garmin MFA [Feature] Research: Options for handling Garmin MFA Jan 14, 2023
@dkmcgowan
Copy link

I had to enable this to use the new ECG feature

@philosowaffle philosowaffle self-assigned this Jan 29, 2023
@philosowaffle
Copy link
Owner Author

philosowaffle commented Jan 29, 2023

After several hours of reverse engineering and tinkering,here is what was learned today:

Non-MFA flow:

  1. GET https://sso.garmin.com/sso/signin
    1. INPUT: pass in some generic/magic params
    2. OUTPUT: you get yourself some Cookies
  2. POST https://sso.garmin.com/sso/signin
    1. INPUT: pass in user credentials
    2. OUTPUT: More stuff in Cookie + ServiceTicket
  3. GET https://connect.garmin.com/?ticket=<ServiceTicket>
    1. INPUT: ServiceTicket
    2. OUTPUT: Cookie updated
  4. Sanity check that we are now officially authenticated
    1. GET https://connect.garmin.com/modern/currentuser-service/user/info
    2. INPUT: Cookie
    3. OUTPUT: user info

MFA flow:

  1. GET https://sso.garmin.com/sso/signin
    1. INPUT: pass in some generic/magic params
    2. OUTPUT: you get yourself some Cookies
  2. POST https://sso.garmin.com/sso/signin
    1. INPUT: pass in user credentials
    2. OUTPUT: MFA Code is sent to user, and we are redirected to a page for entering the Code
  3. POST https://sso.garmin.com/sso/verifyMFA/logainEnterMfaCode
    1. INPUT: The MFA code provided by user + csrf token (from previous redirect)
    2. OUTPUT: Success! ->Cookie updated + redirected + ServiceTicket
  4. GET https://connect.garmin.com/?ticket=<ServiceTicket>
    1. INPUT: ServiceTicket
    2. OUTPUT: this step is failing, cannot proceed

Currently can't see anything wrong or different about the request on step 4, appears to match the request I see being made from the browser. Will need to take a look again later with fresh eyes.

@philosowaffle
Copy link
Owner Author

philosowaffle commented Feb 4, 2023

Good news, without any changes from last week, things are working this morning. I suspect last week I had made too many failed attempts and Garmin was temporarily blocking me from signing in.

Now that I know we can successfully authenticate with Garmin will move to solving the next problems:

  1. Background Sync will likely never work for users with MFA since you'd have to regularly provide your MFA token
  2. Console users need a way to enter their token on manual run
  3. WebUI users need a way to enter their token on manual sync
  4. Github Action users - investigate if there is a way to provide MFA
  5. Docs need to be updated to explain the limitations MFA imposes on P2G (like no auto-syncing)

@philosowaffle philosowaffle pinned this issue Feb 4, 2023
@philosowaffle philosowaffle changed the title [Feature] Research: Options for handling Garmin MFA [Feature] Research: Options for handling Garmin MFA (Two-Factor Auth) Feb 4, 2023
@philosowaffle philosowaffle removed the research needed needs more research by developer label Feb 4, 2023
@philosowaffle philosowaffle changed the title [Feature] Research: Options for handling Garmin MFA (Two-Factor Auth) [Feature] Support for Garmin MFA (Two-Factor Auth) Feb 4, 2023
@philosowaffle philosowaffle added this to the 3.4.0 milestone Feb 4, 2023
@philosowaffle
Copy link
Owner Author

philosowaffle commented Feb 5, 2023

MFA Code valid for 30min.
Auth cookie expires after 1 hr.
can see if we can simulate "remember this device functionality" - needs investigation

Todo:

  • Introduce new setting - Garmin.TwoStepVerificationEnabled
  • API - be able to manage setting via API
  • WebUI - be able to manage setting via WebUI
  • API - do not allow sync if MFA is enabled and token not initialized yet
  • API - create endpoint to Init Garmin Auth and support MFA flow
  • WebUI - create modal to allow user to do MFA flow
  • WebUI - polish
  • Console - allow user to enter MFA code during manual sync
  • Console - test
  • BackgroundSync - not allowed if you have MFA enabled
  • Find way to fail fast on GitHub actions - will not be able to support this flow
  • Docs - update

02/11/23 - progress updated
02/12/23 - progress updated

@philosowaffle
Copy link
Owner Author

Will make a post on #408 with more details once this finished building.

@philosowaffle philosowaffle unpinned this issue Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new feature / improvments WIP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants