Tokens and sessions
The ID token, access token and refresh token onefold issues, how long each lasts, and how they relate to your session and the user's onefold session.
A sign-in produces three tokens and involves two sessions. Each has one job. Knowing which is which settles most questions about expiry, sign-out and storage.
The three tokens
| Token | Format | Job | Lifetime |
|---|---|---|---|
| ID token | Signed JWT (RS256) | Tells your application who signed in. You verify it once, at sign-in. | 1 hour by default, until its exp claim. Use it at sign-in, then discard it. |
| Access token | Opaque string | Authorizes calls to the userinfo endpoints on the user's behalf | 15 minutes |
| Refresh token | Opaque string | Obtains a new access token without a new sign-in | 30 days by default, renewed each time it is exchanged; the sign-in ends after 90 days |
ID token
Returned when the request includes the openid scope.
Verify it, read sub, and start your session. It is proof
of a sign-in that happened; it is not a credential for calling an API.
Access token
Send it as Authorization: Bearer … to read the user's claims:
| Endpoint | Notes |
|---|---|
GET /o/userinfo/ | The OpenID Connect userinfo endpoint. Requires the openid scope. |
GET /api/v1/userinfo/ | The same claims. Does not require openid. |
Access tokens are opaque
An access token is a random string, not a JWT. Do not decode it, and do not use it to authenticate requests to your own API. To check one, call a userinfo endpoint with it.
The one exception is an audience-bound access token. When a request names a protected
resource with the resource parameter, the access token is a signed JWT whose aud is that
resource, for your own API to verify. onefold's userinfo endpoints refuse an audience-bound
token. See Protect your API.
Refresh token
Exchange it at the token endpoint when the access token expires. Every exchange returns a new refresh token and spends the old one. See Keep users signed in, which also covers the configurable lifetimes.
The two sessions
| Session | Belongs to | What it is |
|---|---|---|
| Your application's session | You | Whatever your application uses to remember a signed-in user: a cookie, a server-side record. onefold neither creates nor sees it. |
| The onefold session | The user | The user's sign-in on onefold itself. It lets them skip the sign-in page the next time any application sends them to onefold. |
The two are independent:
- Ending your session does not end the onefold session. onefold has no end-session endpoint. See Sign out and revoke.
- The onefold session ending does not end your session, and does not revoke your tokens.
- How long a user stays signed in to your application is your decision, made by your session. Token lifetimes only limit how long you can keep calling onefold for that user.
Storing tokens
| Application | Where tokens go |
|---|---|
| Server-side web application | On the server, tied to your session. Never send them to the browser. |
| Single-page application | In memory. Not in localStorage or sessionStorage, where any script on the page can read them. |
| Mobile or desktop application | The platform's secure storage, such as the keychain or keystore |
A client secret is a server-side value. An application that cannot keep one is a public client and has none.
When a token stops working
Tokens end by expiry, by revocation, or with the grant they were issued under.
Sign out and revoke lists every case.
An expired or revoked access token is refused with 401; a refresh token that no longer works
answers invalid_grant. In both cases, send the user through sign-in again.
A refresh also answers invalid_grant when the sign-in behind the authorization fails the
organization's security policy: the organization requires a second
factor the user has not provided, the sign-in is older than it allows, or the organization
has asked that user to sign in again. Send the user through sign-in again; the hosted page
asks for what is missing and then returns them to your application.
Accounts, applications and grants
The onefold model — one account per person, applications that request access, and the grant that connects them — and what stays in your own application.
Scopes and claims
Every scope a onefold application can request, the claims each one returns in the ID token and from userinfo, and how scopes relate to consent.