Sessions & Tokens
Two tokens, two jobs
The session token is what your backend verifies. It is signed, carries entitlements, and lives 90 seconds. The refresh token exists only to obtain the next session token; it is long-lived, and it is the one worth protecting.
The numbers
| Default | Configurable | |
|---|---|---|
| Session token | 90 seconds | Only through a JWT template (30 s – 24 h) |
| Session maximum lifetime | 7 days | Project Settings → Auth → Sessions |
| Inactivity timeout | 30 minutes | Same place |
| One-time code | 10 minutes | No |
| Second-factor challenge | 5 minutes | No |
Ninety seconds is short on purpose. A verified token proves it was valid when issued, not that the session is still live — so the window in which a revoked session still passes verification is the token's own lifetime. Short token, small window.
Where each token belongs
The SDKs already do the right thing. This is what they do, and why, so you do not undo it.
- Session token — in memory, never stored. Anything a script can read, an XSS can exfiltrate, and this is a bearer credential. It is never written to
localStorageor a readable cookie. The cost is that a page reload loses it, which is whatrestore()is for. - Refresh token on hosted sign-in — an
httpOnlycookie. Set on your own verified domain, so it is first-party and JavaScript cannot touch it at all.restore()uses it without ever seeing it. - Refresh token on mobile — the platform keystore. iOS Keychain, Android
EncryptedSharedPreferences. The React Native, Expo and Flutter bridges delegate to the native SDKs precisely so this stays true rather than landing inAsyncStorage. - Refresh token cross-origin on the web — in memory only. When you drive the API from an origin that cannot use a first-party cookie, the server returns the refresh token in the response body. The web SDK keeps it in memory and has no public accessor for it, so a page reload loses it and
restore()returnsnull: sessions survive a reload only on your hosted auth domain. (Call the HTTP API directly and the token is in the response you receive; where it goes is then your decision.) This is the reason hosted sign-in runs on your hostname.
Refresh, and what a reused token does
Every refresh rotates: the token you present is retired and a new one comes back. The SDK does this for you ahead of expiry, and concurrent callers share one in-flight request rather than racing.
await auth.restore(); // page load: null if there is nothing to restore
await auth.refresh(); // force one now; rarely neededReuse detection
Every refresh failure — expired, revoked, reused, inactive, wrong environment, wrong project — comes back as the same opaque 401. Distinguishing them in the response would tell an attacker whether the token they hold is real.
What is in the token
{
"iss": "https://api.billdog.io",
"sub": "…", // the USER — who signed in
"cus": "…", // the CUSTOMER — what they own
"sid": "…", // session id
"aud": "<project id>",
"env": "production", // or "sandbox" — load-bearing, see below
"ent": ["pro", "team"],// materialised entitlements
"ent_truncated": false,
"fva": [0, 12], // minutes since first / second factor (-1 = none)
"sts": "active",
"trs": "proven",
"o": { "id": "…", "slg": "acme", "rol": "org:admin" },
"exp": 1234567890, "iat": 1234567800, "nbf": 1234567800, "jti": "…"
}Never read ent as a complete list without checking
ent_truncated is true and the list is incomplete — treating it as the whole set turns a paying customer into a free one. hasEntitlement() in the Node SDK handles this; if you parse the token yourself, check the flag and fall back to introspect(). Truncation is never silent.Listing and ending sessions
// scope: 'this' (default) | 'others' | 'all' | 'session'
await auth.signOut();
await auth.signOut('all');auth-sessions lists a person's devices for an account screen. The IP it returns is coarsened — the final octet or hextet is dropped — so a device is recognisable without being locatable.
Sign-out never throws in the SDKs. It clears local state either way and tells you whether the remote revoke landed, because a sign-out that throws leaves someone looking signed in.
A password reset or change ends sessions too. Completing a reset revokes every session the account has and issues none — the person resetting is proven by an emailed code, not by any session, and the usual reason to reset is that somebody else holds one. A change keeps the caller's own session and revokes all the others. Both publish the revocations to the edge immediately and return sessions_revoked; a device whose session was ended finds its next refresh refused with the same opaque 401 as any other dead token and signs out locally. See Passwords.
Offline verification, and its one limit
Your backend verifies the signature against a cached JWKS — no call to us. The trade is a bounded staleness: for up to 90 seconds, a session you revoked can still verify. When you need certainty inside that window — a "sign out everywhere" that takes effect immediately — call introspect(), which does hit the network and answers whether the session is live right now.
Signing keys are environment-scoped: sandbox and production have separate keys and separate JWKS. A sandbox token cannot verify against production keys, which is why environment is a required decision rather than a convenience.
Next
- Identities — how a person is addressed.
- Quickstart — the end-to-end path.
Was this page helpful?
Or rate this page: