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

TokenFormatJobLifetime
ID tokenSigned 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 tokenOpaque stringAuthorizes calls to the userinfo endpoints on the user's behalf15 minutes
Refresh tokenOpaque stringObtains a new access token without a new sign-in30 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:

EndpointNotes
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

SessionBelongs toWhat it is
Your application's sessionYouWhatever your application uses to remember a signed-in user: a cookie, a server-side record. onefold neither creates nor sees it.
The onefold sessionThe userThe 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

ApplicationWhere tokens go
Server-side web applicationOn the server, tied to your session. Never send them to the browser.
Single-page applicationIn memory. Not in localStorage or sessionStorage, where any script on the page can read them.
Mobile or desktop applicationThe 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.

On this page