Skip to content
Workforce IdentityMarkdown

Refresh tokens

Apps stay signed in without asking the user again, and, with rotation, a stolen refresh token is caught the moment it is used twice.

AvailableAPIRFC 6749 §6, RFC 9700 §4.14

An access token lasts minutes. A refresh token lets the app get a new one without sending the user back to sign in. Only the client it was issued to can use it, and it can narrow what it asks for but never widen it.

A refresh token comes with a browser or device sign-in, never with client credentials. With OpenID Connect it comes only when the user allowed offline_access. With rotation, each use returns a new refresh token, and a copy used a second time ends the whole family, so a stolen token buys almost nothing. Reuse is caught only with rotation: public apps always rotate, but a confidential app reuses its refresh token unless you set rotate.

  • Who can do it: a realm administrator (a group holding RealmOwner) lets a client hold refresh tokens and sets the lifetimes; RealmViewer can read them. The app then refreshes with its own credentials.
  • Where: today this is done through the API (Call the API shows how to get $CVYUH_SESSION).
  • First: the app signs users in with authorization code or device authorization.

The app sends the refresh token to the token endpoint. A public app sends its client_id; a confidential one proves itself as for any grant (client authentication):

Terminal window
curl https://foobar.cvyuh.com/oauth2/token \
-d grant_type=refresh_token \
-d client_id=team-wiki \
-d refresh_token=eyJhbGciOi…
{
"access_token": "eyJhbGciOiJFUzI1NiIs…",
"token_type": "Bearer",
"expires_in": 300,
"scope": "openid profile offline_access",
"refresh_token": "eyJhbGciOi…",
"id_token": "eyJhbGciOiJSUzI1NiIs…"
}

To ask for less, the app adds scope or resource naming part of what it was granted. While openid is still granted, the answer carries a new ID token too.

With rotation, each use spends the refresh token and returns a new one. If a spent token is ever used again, someone has a copy. The realm then ends the whole family: every refresh token descended from the same sign-in, and the access tokens they bought.

  • Public apps always rotate, because they cannot keep a secret.
  • A public app’s family is bound to its DPoP key when its first token was DPoP-bound (DPoP). Every refresh must then carry a proof by the same key.
  • Confidential apps choose, and default to reuse. They prove who they are on every use, so a copied token is useless without the client’s credentials. With reuse, the same token works until its family ends and a second use is never caught; set rotate to have it caught.
  • A retry window lets an app that lost an answer present the same token again for a few seconds. It is off by default and capped at a minute, because inside it whoever presents the token is answered.

These steps use the admin API; Call the API shows how to get a session.

  1. Allow the client to hold refresh tokens: add refresh_token to its grantTypes in https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client, and choose refreshTokenRotation. Read the client first with GET, and send back the whole list with the new value: a list you send replaces the client’s list.
  2. Set the realm’s lifetimes with PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings.
WhereSettingDefaultWhat it does
ClientgrantTypes includes refresh_tokenThe client may hold refresh tokens
ClientrefreshTokenRotationreuserotate catches a reused token; public clients always rotate
RealmrefreshTokenIdleSecs3600 (1 hour)Unused this long, the token stops working
RealmrefreshTokenLifetimeSecs86400 (1 day)The family ends this long after the sign-in, however often it is used
RealmrefreshTokenRetrySecs0 (off)The retry window
RealmrefreshTokenGrantsbrowser and device sign-inThe grants that come with a refresh token

Nothing, while refreshes succeed: the app stays signed in. When a family ends (its lifetime is up, it sat unused past the idle limit, the session ended for an online family, or a reuse was caught), the app’s next refresh is refused and the app sends the user to sign in again.

Setting or limitDefaultRange
refreshTokenLifetimeSecs: the family’s life from sign-in86,400 (one day)1 to 31,536,000 (a year)
refreshTokenIdleSecs: unused this long, it stops3,600 (one hour)0 (no idle limit) to 31,536,000
refreshTokenRetrySecs: the retry window0 (off)0 to 60
refreshTokenRotationreuse; always rotate for a public clientrotate or reuse; a fapi2 client is refused rotate
refreshTokenGrantsbrowser and device sign-inany of the realm’s grants that sign a user in
SymptomCauseFix
Users are sent to sign in again every hourThe app doesn’t refresh within refreshTokenIdleSecsRefresh on each app start, or raise the idle limit
A rotating app is signed out at randomTwo tabs or threads refreshed with the same token: the second use looked like a theft and ended the familyRefresh from one place, or set a short refreshTokenRetrySecs
No refresh token comes backThe client lacks refresh_token in grantTypes, or the user didn’t allow offline_access with OpenID ConnectAdd the grant, and ask for offline_access
A copied token wasn’t caughtThe client uses reuseSet refreshTokenRotation to rotate

Each refresh is a TOKEN_ISSUED record with grantType refresh_token. A caught reuse is a TOKEN_ISSUED record with result FAILED, keyed by the client, with error invalid_grant and reason “the refresh token was already used”; the family it ended is revoked with it. See them in Audit → Authentication, or read the user’s trail (Read a user’s or agent’s trail).

  • A refresh never widens. A scope or resource the family wasn’t granted is refused.
  • The user must still be there. A refresh is refused once the user can no longer be issued tokens, or once they took the app back on their Authorized Apps page (consent).
  • An online family ends with the session. Unless the user allowed offline_access, a refresh is refused once the session they signed in with has ended. See Choose online or offline access.
  • A refresh token is redeemed only at the issuer that gave it. With no base URL, each of the realm’s host names is its own issuer.
ErrorWhen
invalid_requestNo refresh_token is sent
invalid_grantThe token is unknown, expired or another client’s; it was issued under another of the realm’s issuers (another host name, when no base URL is set); it was already used; its family was ended; the DPoP proof is by another key, or an attesting client’s instance is another; or the user, their session or their consent is gone
invalid_scopeA scope the family wasn’t granted
invalid_targetA resource the family wasn’t granted, or none the client may still name