Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

The refresh token grant

An access token is meant to be short-lived, but some applications need to keep working for a person long after the sign-in page has closed. A refresh token lets a client get new access tokens for an authorization the person already gave, without sending them through the flow again.

Access that outlasts a visit

The printer now offers a yearly calendar. Ava connects her photo account once, and every December the printer picks twelve recent photos from her albums and sends her a proof. Ava won't be at her browser in December when the printer needs those photos.

The access token from the code exchange can't cover that gap. It lasted ten minutes, and short lifetimes are deliberate: if a token leaks, it is only useful briefly. The printer needs a way to get new access tokens months later without asking Ava to approve the connection again.

A refresh token is a credential a client uses to get new access tokens for an authorization it already has. It goes only to the authorization server's token endpoint, never to the photo API. The access token is what the photo API sees; the refresh token is what lets the printer ask for another one.

This time, when the printer exchanged its authorization code, the photo service issued a refresh token alongside the access token:

{
  "access_token": "demo-access-token-8",
  "token_type": "Bearer",
  "expires_in": 600,
  "refresh_token": "demo-refresh-token-3",
  "scope": "photos.read"
}

All domains, credentials and tokens in these examples are fictional.

Whether a refresh token is issued is the authorization server's decision, not the client's. Some services issue one only when the client asks for continued access. A common way to ask is the offline_access scope, which OpenID Connect defines: "offline" means the person doesn't have to be present when the client uses the access. Because it changes what Ava is agreeing to, the consent screen usually says so, with a line such as "Keep access when you are not using the app." Other services decide by the kind of client or by their own policy.

The printer's backend stores the refresh token with Ava's connection record and protects it like any other long-lived secret, because it is the part that carries her approval forward. Each access token is used for a short while and then discarded.

Refreshing an access token

In December, the printer's backend sends the refresh token to the token endpoint with grant_type=refresh_token. There is no browser, no redirect, no authorization code and no PKCE verifier this time. The printer is a confidential client, so it authenticates with its client ID and secret in the Authorization header, as it did during the code exchange:

POST /token HTTP/1.1
Host: auth.photos.example
Authorization: Basic cGhvdG8tcHJpbnRlcjpkZW1vLW9ubHktbm90LWEtcmVhbC1zZWNyZXQ=
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token
&refresh_token=demo-refresh-token-3

The authorization server checks four things before it answers. The client must authenticate. The refresh token must have been issued to this client. The refresh token must still be valid. And the authorization behind it must still exist: if Ava had disconnected the printer from her photo account, the token would no longer be honored.

Client authentication matters here because it ties the refresh token to the printer. Someone who copied the refresh token out of the printer's database still couldn't use it without the printer's secret.

The request can include a scope parameter to ask for less than the original grant, for example a token for one purpose only. It can't ask for more. A refresh token carries forward what Ava approved, and broader access needs a new authorization request where she can say yes or no.

A successful response returns a new access token, which the printer uses at the photo API exactly as before.

When the refresh token is replaced

The response may also contain a different refresh token:

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache

{
  "access_token": "demo-access-token-9",
  "token_type": "Bearer",
  "expires_in": 600,
  "refresh_token": "demo-refresh-token-4",
  "scope": "photos.read"
}

As with the code exchange, Cache-Control: no-store and Pragma: no-cache tell anything between the server and the printer not to keep a copy of a response that holds tokens.

This is refresh token rotation: each refresh token works once, and each successful refresh hands the client its replacement. The printer stores demo-refresh-token-4 in place of demo-refresh-token-3 before it relies on the new access token. When a response carries no replacement, the printer keeps the refresh token it already has.

Rotation gives the server a way to notice theft. If an old refresh token comes back after it has been replaced, either the printer has a bug or someone else has a copy, and the server can't tell which. A cautious server refuses it and may revoke the whole chain of refresh tokens that grew from Ava's authorization. That is why the printer refreshes a connection from one worker at a time, and why it treats a lost refresh response with the same caution as a lost code exchange: resending the old refresh token is not a safe retry.

With rotation, each refresh returns a replacement refresh token. The printer keeps only the newest one, and an old one presented again is refused.

Refresh tokens and rotation follows the server's side: what it keeps, and what it revokes when a used token returns.

When refresh stops working

Refresh tokens don't last forever. They can expire, go unused for too long, or be revoked because Ava disconnected the printer, changed a security setting, or the service detected reuse. The token endpoint then answers with invalid_grant, the same error a used or expired authorization code produces.

The printer can't repair that on its own. Retrying the same refresh token won't help, and it has no other way to get access Ava hasn't approved again. The right response is to mark the connection as needing attention, then ask Ava to reconnect the next time she visits, or send her a notice that December's calendar is waiting for her photos.

The printer's secret protects its refresh tokens, but a public client, such as an application running entirely in the browser, has no secret to prove who is presenting a refresh token. Current security guidance requires servers to protect those refresh tokens another way: by rotating them, or by binding each one to a key the client holds, so a copy is useless without that key. Token revocation and Refresh token theft look at how stolen refresh tokens are used and contained.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

The printer refreshes Ava's connection and the response holds a new refresh token. What should it do with the one it sent? 1 of 3

Choose one answer.

In December the token endpoint answers the printer's refresh request with invalid_grant. What should the printer do? 2 of 3

Choose one answer.

Ava approved photos.read for the calendar. The printer now wants to add finished calendars to her albums. What happens if it asks for photos.write in a refresh request? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity