Skip to content
Workforce IdentityMarkdown

Keep apps signed in

Let apps renew their access without asking users to sign in again, choose how refresh tokens rotate, and catch a stolen one.

APIRFC 6749, RFC 9700

An access token lives five minutes by default, and most users stay longer. With a refresh token, the app swaps it for a fresh access token in the background, and the user keeps working without being sent back to sign in. You choose whether a confidential app’s refresh tokens rotate, and how long they last.

Before you start:

  1. Let the app hold refresh tokens: its grantTypes include refresh_token. With OpenID Connect, a refresh token comes only when the user allows offline_access: see Choose online or offline access.

  2. Choose rotation for a confidential app. A public app always rotates.

    Terminal window
    curl -X PATCH 'https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/<client-id>' \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "refreshTokenRotation": "rotate" }'

    A client held to FAPI 2.0 is refused rotate: its refresh tokens are not rotated. See Hold a client to FAPI 2.0.

  3. Optionally, change the lifetimes for the realm. These are the defaults:

    Terminal window
    curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "refreshTokenIdleSecs": 3600, "refreshTokenLifetimeSecs": 86400,
    "refreshTokenRetrySecs": 0 }'

    refreshTokenRetrySecs lets an app that lost an answer use the same token again within that many seconds, up to 60. Anyone holding the token is answered inside the window, so leave it at 0 unless an app needs it.

It posts grant_type=refresh_token to https://foobar.cvyuh.com/oauth2/token, authenticating as it did for the code, and gets a new access token. With rotation, it also gets a new refresh token, and must keep only the newest. It may ask for fewer scopes or APIs than it was granted, never more.

A refresh token unused for an hour stops working. However much it is used, the whole chain ends a day after the sign-in, and the user signs in again. If the user removed the app, the account was deactivated, or the client was turned off, the refresh is refused.

The app…RotationWhat a thief with a copy can do
is public (browser, mobile)Always onUse it once at most. The next use of either copy ends the whole family, the thief’s and the app’s
is confidential, set to rotateOnThe same, and the thief also needs the client’s own credentials
is confidential, set to reuseOffNothing without the client’s credentials. End the family by revoking the token

When the family ends, the app’s next refresh fails and the user signs in again. That is the signal that something is wrong. Reuse is caught only where tokens rotate: a confidential app left at reuse, the default, never trips it.

Sign in to the app, wait for its access token to expire, and use it again: the app should refresh without sending you to sign in. Under rotation, the token response carries a new refresh_token each time.

Every refresh is on the user’s trail as a TOKEN_ISSUED record with grantType refresh_token. A reuse that ended a family is a TOKEN_ISSUED record with result FAILED, under the client’s ID, with error invalid_grant and reason “the refresh token was already used”. Find them in Audit → Authentication in the dashboard.

SymptomCauseFix
Users are sent to sign in after an hour awayThe refresh token was idle past refreshTokenIdleSecsRaise it, up to the family’s lifetime
Users are sent to sign in once a day, however activeThe family reached refreshTokenLifetimeSecsRaise it, or accept a daily sign-in
invalid_grant, “already used”, with no theftTwo tabs or workers refreshed with the same rotating token at onceHave the app share one refresh at a time, or set refreshTokenRetrySecs to a few seconds
No refresh token comes backThe app lacks refresh_token in grantTypes, or the user didn’t allow offline_accessSee step 1
Setting rotate is refusedThe client is held to FAPI 2.0Leave it at reuse

PATCH the client with { "refreshTokenRotation": "reuse" }, and the realm’s lifetimes back to the values above.