Sessions
A session is a signed-in principal’s standing permission to act, from sign-in until it ends. Its token, agp_st_…, is shown only in the answer that starts the session, and the session record holds only its hash. Every request made with the token acts as the session’s principal.
How a session starts
Three sign-ins start a session, each from a browser or a native app with the publishable key, or from your server with the secret key:
- An emailed code.
POST /auth/email-codesends a 6-digit code, andPOST /auth/email-code/verifytakes it back with theverificationId. A code lastssignIn.emailCode.codeTtl, 10 minutes in a new project. If the last code for the address is unused and still withinsignIn.emailCode.resendAfter, 30 seconds in a new project, another request answers with the sameverificationIdand sends no code. A verification allows 5 guesses. - An OAuth provider, such as Twitch, from
POST /auth/oauth/:providerKey/startto its callback. The same flow also links a provider login to a signed-in principal, or connects its account at the provider for later use. - A guest, with
POST /auth/guest, when your config allows guests.
A first sign-in with a code or a provider creates the principal when the sign-up mode allows it, and says so with signedUp: true. A guest that signs in with a new identity also gets signedUp: true. Requesting a code reveals nothing about whether the address already has an account. When the address has no account and the sign-up mode wouldn’t let it in, as in a closed project or for an address without an invitation in an invite_only one, no email goes out: the request answers as usual, and verifying its verificationId fails with code_invalid, like a wrong code.
| Limit | Value |
|---|---|
| Code requests per address | 5 per 15 minutes |
| Code requests per IP address | 30 per 15 minutes |
| Code verification calls per IP | 50 per 15 minutes |
| OAuth starts per IP address | 30 per 15 minutes |
Past a limit, the request answers throttled with details.retryAfter in seconds. A browser’s own requests count against its IP address. When your server makes them, pass the visitor’s address as the server helpers do.
How long it lasts
In a new project, a session ends after 7 days without use (sessions.idleTtl), and 30 days after it started at the latest (sessions.maxTtl), whichever comes first. Use of the session token moves the idle limit forward at most once a minute. Your server introspecting the token counts as use, so an app that only calls your server stays signed in while your server checks its token. Calls with a Platform user token leave it as it is. A guest’s session has the guests’ idle limit, guests.idleTtl, 30 days in a new project, and no sessions.maxTtl cap, since it is the guest’s only way back.
A session also ends when:
- The principal signs out, or revokes it, or all its other sessions, from the signed-in principal.
- The principal is suspended or deleted.
- A sign-in identity is removed, and the session uses the same authentication method. The session used to remove it stays active.
- A guest signs in with a new identity or merges into another principal.
- The principal’s account merges into another account. The survivor’s sessions stay active.
An ended session’s token answers unauthenticated.
The tokens a session leads to
- User tokens. A page can send a short-lived Platform user token minted from the session instead of the session token.
- Delegated tokens. A delegated token is a session of kind
delegatedthat acts as the delegator for its delegate; Delegations describes it.
A session records how it started (authMethods) and any client IP or user agent recorded for it (client), so a principal can tell its sessions apart.
Where the session token is kept
The SDK’s session strategies explain where a session token can be kept and when your page can read it.
Checking a session on your server
Your server learns who a token acts for with the SDK’s server helpers or Introspect a token.
Where to act on it
- The IdentityHound quickstart signs a principal in, Add email sign-in builds a sign-in screen, and Keep the session on your server keeps the token in a cookie.
- Sign-in starts, ends, and introspects sessions.
- The signed-in principal lists and revokes a principal’s own sessions.