Add opt-in Moen SSO (Cognito) auth for migrated accounts#71
Open
ajplotkin wants to merge 1 commit into
Open
Conversation
Flo accounts migrated to the Moen Smart Water Network now authenticate via a Cognito access token; api-gw rejects the legacy users/auth token with 401. Add an opt-in use_sso flag: exchange username/password at the SSO oauth2/token endpoint, use the access token as a Bearer, and resolve the user id from /users/me (the SSO token doesn't embed it). Legacy flow unchanged and remains the default (backwards compatible). Verified: SSO Bearer path authenticates against api-gw /users/me on a real migrated account. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
Flo accounts that have been migrated to the Moen Smart Water Network now
authenticate through Moen's SSO (Cognito), and
api-gw.meetflo.comrejects the legacyusers/authtoken with401. For migrated accounts, the current flow logs insuccessfully at
api.meetflo.com/api/v1/users/authbut the returned token then fails onevery
api-gwv2 call — which breaks Home Assistant's built-inflointegration (andanything else built on aioflo) for those users.
Verified against a real migrated account:
users/authtoken →401onGET api-gw.meetflo.com/api/v2/devices/{id}and/users/{id}POST oauth2/token {username, password, client_id}(nogrant_type) →{ "token": { "access_token", "refresh_token", "expires_in", ... } }Authorization: Bearer <token>, →200on the same v2 endpointsOnly the auth changed; valve control etc. on api-gw v2 are unchanged.
Change
Adds an opt-in
use_ssoflag (defaultFalse, so existing behavior is unchanged):use_sso=Trueexchanges username/password at the SSOoauth2/tokenendpoint,uses the Cognito access token as a Bearer token, and resolves the user id from
GET /users/me(the SSO token, unlike the legacy token, doesn't embed it).users/authpath is untouched and remains the default.Testing
Adds
test_get_api_sso(plussso_auth_success_response/sso_users_me_responsefixtures) covering the SSO flow and asserting the token is sent as a bearer token —
tests/test_api.pypasses (4/4), including the existing legacy tests unchanged.I also verified live against a migrated account that the
use_ssopath authenticatessuccessfully to
api-gw.meetflo.com/api/v2/users/me.Happy to adjust the default behavior (e.g. auto-detect / fallback) or the API shape
however you prefer — this is intentionally minimal and non-breaking.