What Is an OAuth 2 Refresh Token?
An OAuth 2.0 refresh token is a credential a client exchanges at the authorization server’s token endpoint for a new access token, without sending the user back through sign-in. It lets you keep access tokens short-lived, often minutes, while users stay signed in for hours or days. The client never sends the refresh token to an API; only the authorization server accepts it.
Two recent RFCs now set the baseline. RFC 9700, the OAuth 2.0 Security Best Current Practice (January 2025), requires refresh tokens issued to public clients, such as single-page and mobile apps, to be either rotated on every use or bound to a key the client holds. RFC 10017 (August 2026) sets out how browser-based apps should handle them. This guide covers the request format, errors, lifetimes, rotation, storage and revocation, with examples.
Access Tokens vs. Refresh Tokens
An access token proves to an API that the caller may do something; a refresh token proves to the authorization server that the client may get another access token. They differ in audience, lifetime and how much damage a leak causes.
| Access token | Refresh token | |
|---|---|---|
| Sent to | APIs (resource servers), on every call | The authorization server’s token endpoint only |
| Typical lifetime | Minutes | Hours to days, with an idle timeout |
| Format | Often a signed JWT that APIs validate locally | Usually an opaque string only the server can look up |
| Revocation | Hard to revoke before expiry if APIs validate it locally | Revoked at the server; the next refresh fails |
| Impact if stolen | API access until it expires | New access tokens until it is revoked, rotated out or expires |
How the Refresh Token Grant Works
The refresh flow is defined in section 6 of RFC 6749. The client receives a refresh token together with its first access token, then uses it whenever the access token expires or is about to.
- The user signs in, usually through the authorization code flow with PKCE, and the token endpoint returns an access token and a refresh token. OpenID Connect providers usually issue a refresh token only when the client requests the
offline_accessscope. - The client calls APIs with the access token until it expires or an API returns 401.
- The client sends the refresh token to the token endpoint with
grant_type=refresh_token. - The server checks the token, the client and the requested scope, then returns a new access token and, if it rotates refresh tokens, a new refresh token.
- The client replaces both stored tokens and retries the API call.
Refresh request and response example
The request is a form-encoded POST. A confidential client, such as a server-side web app, must authenticate, here with HTTP Basic. A public client has no secret, so it sends its client_id in the body instead.
POST /token HTTP/1.1
Host: auth.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA
A successful response returns a new access token. With rotation, it also returns a new refresh token, and the client must discard the old one.
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{
"access_token": "eyJhbGciOiJSUzI1NiIs...",
"token_type": "Bearer",
"expires_in": 600,
"refresh_token": "8xLOxBtZp8...",
"scope": "read:invoices"
}
Three request rules trip people up. scope is optional; if you send it, it can only narrow the original grant, never add to it. Omitting it means the original scope. And a refresh token belongs to the client it was issued to, so another client can’t use it.
Refresh errors and what to do about them
When a refresh fails, the server returns HTTP 400 (or 401 for a client authentication failure) with an error code from RFC 6749 section 5.2. Handle each code differently:
| Error | Meaning | What the client should do |
|---|---|---|
invalid_grant | The refresh token is invalid, expired, revoked, already used under rotation, or was issued to another client | Clear stored tokens and send the user through sign-in again. Don’t retry with the same token. |
invalid_client | Client authentication failed | A configuration problem, such as a rotated client secret. Alert, don’t loop. |
invalid_scope | The requested scope exceeds what was originally granted | Drop the extra scope, or ask the user to consent again. |
Refresh Token Lifetimes and Expiration
Set two limits on every refresh token: an idle timeout, after which an unused token expires, and an absolute maximum lifetime, after which the user signs in again however active they are. RFC 9700 says refresh tokens should expire after a period of client inactivity, and RFC 10017 requires browser-app deployments to set a maximum lifetime or an idle expiry.
RFC 10017 adds a rule for rotation. When a refresh token has a preestablished expiration time, a newly issued refresh token must not extend the lifetime beyond that of the initial refresh token. Its worked example pairs a 10-minute access token with an 8-hour refresh token, so the session ends after eight hours even if the token is rotated many times. Pick values by risk: hours for a banking or admin console, days or weeks for a low-risk consumer app.
Also decide what ends a refresh token early. RFC 9700 allows servers to revoke refresh tokens on security events such as a password change or logout. Revoking them when an admin disables the account is common practice rather than an RFC rule, and worth doing.
Refresh Token Rotation and Reuse Detection
With rotation, every successful refresh returns a new refresh token and invalidates the one just used. If a stolen token is used after the legitimate client has already used it, or vice versa, the server sees a retired token come back. RFC 9700 explains that the server can’t tell which party is the attacker, so it revokes the active refresh token, ending the session for both. The user signs in again; the attacker is locked out.
RFC 9700 says refresh tokens issued to public clients must be sender-constrained or use refresh token rotation. The current OAuth 2.1 draft carries the same requirement.
Rotation has two failure modes to design for:
- Lost responses. If the network drops the response to a refresh request, the client is left holding a token the server has already retired, and the next refresh fails. The OAuth 2.1 draft calls this out. Many servers allow a short grace window in which the old token still works.
- Concurrent refreshes. Two parallel API calls that both get 401 can both try to refresh with the same token. The second request presents a retired token and can trigger reuse detection, logging the user out. Make refresh single-flight, as shown below.
Making refresh single-flight
Share one in-progress refresh across all callers so the token endpoint sees one request per refresh. This example assumes a token-mediating backend: the backend keeps the refresh token and exposes a /auth/refresh route that returns a new access token to the browser. It ends the session only when the backend says the refresh token is no longer valid, and leaves server errors and network failures to be retried:
class SessionExpiredError extends Error {}
class RetryableRefreshError extends Error {}
let pendingRefresh = null;
function refreshAccessToken() {
if (!pendingRefresh) {
pendingRefresh = fetch("/auth/refresh", { method: "POST", credentials: "include" })
.then((response) => {
if (response.status === 401) {
throw new SessionExpiredError();
}
if (!response.ok) {
throw new RetryableRefreshError(response.status);
}
return response.json();
})
.finally(() => {
pendingRefresh = null;
});
}
return pendingRefresh;
}
Catch SessionExpiredError by sending the user to sign in, and retry RetryableRefreshError with backoff. In a full backend-for-frontend, the browser never receives tokens at all and the backend refreshes on its own; the single-flight rule then applies inside the backend. This covers one browser tab. If the app is often open in several tabs, coordinate across them as well, for example with the Web Locks API, so only one tab refreshes at a time.
Sender-Constrained Refresh Tokens (DPoP)
Sender-constraining binds a refresh token to a key only the legitimate client holds, so a copied token is useless on its own. With DPoP (RFC 9449), a public client creates a key pair, signs a short proof for each token request, and the server binds the refresh token to that public key. Every later refresh must carry a proof signed with the same key.
DPoP avoids rotation’s lost-response and race problems, because the token itself doesn’t change. The server can bind only the refresh token and still issue ordinary bearer access tokens. Confidential clients don’t need DPoP for refresh tokens, because client authentication already ties the token to them. Check that your authorization server supports DPoP before planning around it.
Where to Store Refresh Tokens
Store the refresh token where the least code can read it. The right place depends on the app type:
| App type | Recommended storage |
|---|---|
| Server-side web app | Server-side session store, encrypted at rest. The browser only gets a session cookie. |
| Single-page app | Ideally not in the browser at all: a backend-for-frontend (BFF) holds it and the browser gets a cookie, as described below. |
| Mobile app | The platform’s secure storage: Keychain on iOS, Android Keystore-backed storage on Android. |
| Machine-to-machine | Usually no refresh token; the client credentials grant gets a new access token directly. |
For browser apps, RFC 10017 ranks the architectures from most to least secure: a backend-for-frontend, a token-mediating backend, then a pure in-browser client. In the BFF pattern the backend is a confidential client that holds the refresh token server-side and gives the browser a session cookie. That cookie must be Secure and HttpOnly, should use SameSite=Strict, and should use the __Host-Http- name prefix. Keep refresh tokens out of localStorage and sessionStorage, where any injected script can read them.
Revoking Refresh Tokens on Logout
Logging out should revoke the refresh token at the server, not just delete it from the client. RFC 7009 defines a revocation endpoint that takes the token and an optional token_type_hint:
POST /revoke HTTP/1.1
Host: auth.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded
token=8xLOxBtZp8...&token_type_hint=refresh_token
The server returns 200 even if the token was already invalid, so treat 200 as done. RFC 7009 also says that if the server supports revoking access tokens, revoking a refresh token should invalidate the access tokens issued from the same grant. Whether that takes effect immediately depends on how your APIs validate access tokens, which is one more reason to keep access tokens short-lived.
When to Use Refresh Tokens
Use refresh tokens when users need to stay signed in longer than an access token should live: web apps with persistent sessions, mobile apps, and background jobs acting for a user. Skip them for one-off access, for machine-to-machine calls that can request a new token, and in high-risk contexts where you want users to sign in again when the access token expires. RFC 9700 asks servers to decide, based on a risk assessment, whether to issue refresh tokens at all.
Refresh Token Best Practices: Checklist
- Keep access tokens short-lived, minutes rather than hours.
- Rotate refresh tokens, or sender-constrain them with DPoP, for every public client.
- Set both an idle timeout and an absolute maximum lifetime, and don’t let rotation extend the session past the original lifetime.
- Make refresh single-flight in the client to avoid false reuse alarms.
- Treat
invalid_grantas “sign in again”; never retry it in a loop. - Keep refresh tokens out of browser storage; use a backend-for-frontend for browser apps.
- Revoke refresh tokens on logout, password change and account disablement.
- Log refresh and reuse events and alert on spikes; reuse is a possible sign of token theft.
- Request only the scopes you need; a refresh can narrow scope but never widen it.
Refresh Tokens in Frontegg
Frontegg issues short-lived JWT access tokens with refresh tokens, and its authentication documentation describes how refresh works:
- Rotation is on by default. Each successful refresh issues a new refresh token and retires the one that was used. You can turn rotation off with the
rotateRefreshTokens:falseconfiguration setting, but for public clients RFC 9700 then requires sender-constrained tokens instead. - A grace window handles lost responses. For about 30 seconds after a refresh, replaying the old token returns a new access token together with the same new refresh token. After the window, the request fails with a 401 (
Refresh token is not found). The grace window doesn’t apply to machine-to-machine (client credentials) refresh tokens. - The SDKs refresh for you. With
keepSessionAlive:true, the SDK refreshes at 80% of the JWT’s lifetime, and Frontegg recommends a JWT expiry of no more than a few minutes. - Lifetimes are configurable. The Security Center token management settings cover refresh token expiration (24 hours by default), rotation, maximum lifetime and sliding expiration. To follow the RFC 10017 rule above, set a maximum lifetime when you use sliding expiration.
Logging out through Frontegg’s logout endpoint invalidates the refresh token server-side, not only in the browser. For how tokens carry tenant context in a B2B product, see our guide to multi-tenant architecture, and the OIDC guide for how ID tokens fit alongside access and refresh tokens.
Put this into practice with Frontegg
Frontegg is customer identity and access management (CIAM) for B2B SaaS. It's free up to 7,500 monthly active users, including 5 SSO/SCIM connections.
Start for freeThe Complete Guide to SaaS Multi-Tenant Architecture
Read the guide