Concepts
Guarantees
What Authyra promises about sessions and tokens, and what it leaves to you.
These are the behaviors Authyra commits to. Each one links to the tests that reproduce the failure it prevents.
Refresh
- At most one refresh per session at a time. Concurrent callers share it. A rotating refresh token is never presented twice by the same app instance. Tests: concurrent callers share a single refresh, 20 concurrent 401s share a single refresh.
- The latest refresh token is always the one used. A refresh that starts after another one finished uses the token it produced. Tests: switchTo during a refresh keeps the rotated refresh token, a refresh finishing after a new sign-in keeps the newer tokens.
- A 401 does not cause a refresh if the token was already replaced. The caller gets the new token directly. Tests: a 401 on a token already replaced returns the new one.
- Transient failures never end a session. Network errors, timeouts and server errors keep it and are retried with backoff. A session ends when the server rejects its refresh token, or, for a session that cannot be refreshed, when its access token is rejected or expires. Tests: a transient failure keeps the session, a long outage keeps a bounded retry rate, a 401 without refresh support ends the session.
Persistence
- A change is visible only once persisted. After a sign-out returns, a restart cannot bring the session back. Tests: a failed sign-out write leaves memory and state unchanged.
- Rotated tokens are never lost to a failed write. They are kept in memory and written again until the write succeeds or the instance is disposed. Tests: rotated tokens survive a failed write, dispose writes tokens kept in memory after a failed write.
dispose()waits for writes in progress, so another instance started afterwards reads the latest tokens. Tests: dispose persists a refresh in flight for the next instance.
Sign-out
- Sign-out wins over refresh. No refresh starts once a sign-out begins; one already in flight is awaited (up to 10 seconds) so the server revokes the newest tokens. Tests: no refresh starts while the session is being signed out, signOut during a refresh revokes the rotated refresh token.
- A server-side revocation failure never blocks the local sign-out. Tests: a failing server-side sign-out still removes the session locally.
- A new sign-in wins over a pending sign-out. If the same user signs in again while their sign-out is still revoking, the new session is kept. Tests: a sign-in completing during signOut keeps the new session.
Accounts
- Sessions are isolated. A request made with one account's token is never retried with another account's token, even after a switch. Tests: a 401 refreshes the account the request was sent with, a 401 for another account refreshes that account.
- A refresh is not a state change.
AuthSignedInchanges when the active account changes, not when its tokens do. Tests: a token refresh is an event, not a state change.
Secrets
- Authyra never prints token values. The
toString()of sessions, tokens and events hides them, and Authyra's own log messages never include them. Tests: toString never exposes tokens. - OAuth security parameters cannot be overridden.
OAuth2Providergeneratesstate, a PKCE verifier and anoncefor each sign-in and checks them on return;BackendOAuthProviderchecksstate. Extra authorization parameters cannot replace them. Tests: extra parameters cannot override the security parameters, rejects a mismatched state, rejects a replayed nonce, rejects a mismatched state.
What stays your responsibility
- Your backend verifies tokens. Authyra trusts what your provider returns; it does not validate JWT signatures on the device.
- Your provider classifies errors. Throw
RefreshRevokedExceptiononly for a definitive rejection (invalid_grant, 401). Anything else is treated as temporary. - One device, one app instance. Coordination is per
Authyrainstance. Two processes sharing a refresh token (an app and its extension, two browser tabs) need a single owner or a server that tolerates it. - Storage confidentiality depends on the platform. On the web, any script on your origin can read what the app can.