Keep users signed in

Exchange a refresh token for a new access token, and handle refresh token rotation and reuse detection.

An access token expires after at most 15 minutes. Exchange the refresh token for a new one instead of sending the user through sign-in again.

Your own session decides how long a user stays signed in to your application. You need the refresh token only while you still call onefold on the user's behalf.

The request

POST https://onefold.eitozx.com/o/token/, form-encoded:

ParameterValue
grant_typerefresh_token
refresh_tokenYour current refresh token
client_idYour client ID
client_secretConfidential clients only
curl -X POST https://onefold.eitozx.com/o/token/ \
  -d grant_type=refresh_token \
  -d refresh_token=REFRESH_TOKEN \
  -d client_id=YOUR_CLIENT_ID \
  -d client_secret=YOUR_CLIENT_SECRET

The response has the same shape as the token exchange.

Rotation

Every refresh returns a new refresh token, and the one you sent is spent. Save the new refresh token before you use the new access token. An application that keeps the old one stops working at its next refresh.

Reuse detection

A spent refresh token presented again is a sign that two parties hold the same token.

When the spent token is presentedWhat happens
Within 10 seconds of the refresh that spent itThe request is accepted. This covers a retry after a network timeout.
Later than thatonefold revokes every token descended from the original sign-in. The user must sign in again.

The 10-second window is for retries, not for concurrency. If your application can refresh from two places, for example two server processes or two browser tabs, make sure only one refresh runs for a given refresh token.

Lifetimes

TokenDefaultConfigurable range
Access token15 minutes5 to 15 minutes
ID token1 hour5 minutes to 1 hour
Refresh token30 days, renewed each time it is exchanged1 to 90 days

A refresh token renews with every exchange, so it expires only after the configured period of inactivity. A sign-in as a whole ends 90 days after the user authorized your application, however often you refresh, and the user must sign in again. That limit cannot be changed.

Setting your own lifetimes, on the OAuth2 tab under Token lifetimes, is a plan feature, and only shortens the access and ID tokens. See Plans and limits. expires_in in each token response always states the access token's actual lifetime.

When a refresh fails

A refresh answers 400 with {"error": "invalid_grant"} when the refresh token has expired, was spent outside the retry window, or was revoked. Send the user through sign-in again.

The retry window applies only to rotation. A refresh token that was revoked on purpose is refused at once. See Sign out and revoke.

The 429 responses of the token endpoint apply to refreshes too. See Token exchange.

On this page