Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io

    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

     DefaultConfigurable
    Session token90 secondsOnly through a JWT template (30 s – 24 h)
    Session maximum lifetime7 daysProject Settings → Auth → Sessions
    Inactivity timeout30 minutesSame place
    One-time code10 minutesNo
    Second-factor challenge5 minutesNo

    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 localStorage or a readable cookie. The cost is that a page reload loses it, which is what restore() is for.
    • Refresh token on hosted sign-in — an httpOnly cookie. 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 in AsyncStorage.
    • 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() returns null: 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.

    Code
    await auth.restore();   // page load: null if there is nothing to restore
    await auth.refresh();   // force one now; rarely needed

    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

    Claims
    {
      "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": "…"
    }

    Listing and ending sessions

    Code
    // 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

    Was this page helpful?

    Or rate this page:

    We use cookies and process your data to provide our services. By continuing, you agree to our Terms and Privacy Policy.