Skip to content

Sessions and tokens

Access tokens, refresh tokens, how long a session lives, and how to end one, including sessions that never expire.

Applies to EngineCloud
View as Markdown
On this page
  1. The access token
  2. The refresh token rotates
  3. How long a session lives
  4. Ending sessions
  5. Signing keys

A signed-in person or machine holds two things.

What it isLifetimeWhere it lives
Access tokenA JWT signed by the project, sent on every request1 hour by defaultIn memory (the SDK)
Refresh tokensyp_rt_…, a long random string that gets a new access tokenAs long as the sessionSecure storage, or an HttpOnly cookie

The access token

Signed with EdDSA (Ed25519). Your own servers can verify it without calling the engine, with the public keys at /.well-known/jwks.json.

JSON
{
  "iss": "https://<ref>.data.sypnia.com/auth/v1",
  "sub": "7c0e…",
  "aud": "authenticated",
  "role": "authenticated",
  "exp": 1795000000, "iat": 1794996400, "jti": "…",
  "session_id": "b1f2…",
  "aal": "aal1",
  "amr": [{ "method": "password", "timestamp": 1794996400 }],
  "email": "ana@example.com",
  "app_metadata": { "provider": "email" },
  "user_metadata": { "name": "Ana" }
}

role is the database role the Data API uses. user_metadata is left out when it is larger than 2 kB, to keep tokens small; read it with getUser().

The refresh token rotates

Every use returns a new refresh token and retires the old one. If a retired token comes back after the reuse window (10 seconds, for two tabs refreshing at once), the engine assumes it was stolen: it ends the whole session and writes refresh_token_reuse to the audit log. The person signs in again; the thief’s copy is dead.

How long a session lives

Each project has a session policy. Every value can be changed in the console or with the API, and each limit can be never:

SettingDefaultValues
access_token_ttl3 600 s300 to 86 400 s
session_lifetimeneverseconds (at least 60), or never
inactivity_timeoutneverseconds since the last refresh (at least 60), or never
single_sessionoffon: a new sign-in ends the user’s other sessions
refresh_reuse_interval10 s0 to 60 s

A value outside its range is refused with 400 invalid_session_policy, and the message names the field and its range; the same goes for a client’s own policy. A new policy applies to sessions that start after it; the settings are cached for up to a minute.

Machines signed in with the device flow follow their client’s policy instead, so an agent can keep a session that never expires while your users’ sessions end after 30 days.

Ending sessions

  • signOut() ends this device; signOut({ scope: 'others' }) the others; signOut({ scope: 'global' }) all.
  • A person lists their devices with sessions.list() and ends any of them.
  • An admin (secret key or the console) can end every session of a user, ban a user until a date, or delete them.
  • Changing a password ends every other session.

Signing keys

Each project has its own Ed25519 keys, encrypted at rest (with AWS KMS in Sypnia Cloud, or with your master key when you self-host). To rotate: a new key is published in the JWKS first, used for signing 24 hours later, and the old one stays published until every token it signed has expired. No one is signed out.

  1. The access token
  2. The refresh token rotates
  3. How long a session lives
  4. Ending sessions
  5. Signing keys

    Search pages, sections and terms