feat(auth): persist the trust token returned by the SSO exchange #29
Reference in New Issue
Block a user
No description provided.
Delete Branch "feat/sso-trusted-device"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What & why
Pairs with website#108, which makes "trust this device" actually work for SSO sign-ins. Two things reach this device when the user ticks the box on the TOTP form:
rg_trustcookie in the Custom Tab. Custom Tabs share the system browser's cookie jar, so that alone makes the next SSO sign-in skip the TOTP step — no app change needed for that half.trustTokenin the/auth/mobile/sso/exchangeresponse — which is what this PR stores. That covers the app's native password login on the same device, which already reads the token back out ofTrustTokenStoreand replays it asX-Trust-Token.MobileTokenResponsealready carriedtrustToken(the native login path has always persisted it) —SsoAuthManagersimply dropped it on the floor. Now it saves it, scoped to the signed-in username exactly likeAuthRepository.logindoes, so it is never replayed for a different account on a shared device; and saves it beforeonSignedInso a process death mid-callback can't lose it.How it was tested
SsoAuthManagerTest: the token is persisted and scoped to its owner (tokenFor("mallory")is null); an absent token leaves the store untouched. Uses an in-memoryFakeTrustTokenStorematching the file's existing fake style../gradlew testDebugUnitTest --rerun-tasks -Pksp.incremental=false).Checklist
AI-assisted contributions (required)
Claude Code (Opus 5). I have reviewed and understandevery change, and take responsibility for it. AI-authored commits are
marked with a
Co-Authored-By/Assisted-Bytrailer.License
(GNU GPL v3.0 or later), and I have the right to contribute it.
Pairs with website feat/sso-trusted-device, which makes "trust this device" work for SSO sign-ins. Two things reach this device when the user ticks the box: 1. The rg_trust COOKIE in the Custom Tab. Custom Tabs share the system browser's cookie jar, so that alone makes the next SSO sign-in skip the TOTP step — no app change needed for that half. 2. A trustToken in the /auth/mobile/sso/exchange response, which is what this commit stores. That covers the app's NATIVE password login on the same device, which reads the token back out of TrustTokenStore and replays it as X-Trust-Token. MobileTokenResponse already carried trustToken (the native login path has always persisted it) — SsoAuthManager simply dropped it on the floor. Save it scoped to the signed-in username, exactly like AuthRepository.login does, so it is never replayed for a different account on a shared device; and save it before onSignedIn so a process death mid-callback can't lose it. Tests: 2 new cases in SsoAuthManagerTest (token persisted + scoped to its owner; absent token leaves the store untouched), with an in-memory FakeTrustTokenStore matching the file's existing fake style. Full unit suite green: 266 tests. Co-Authored-By: Claude <noreply@anthropic.com>