Offline access and refresh behavior
An OpenID ConnectAn identity layer on top of OAuth 2.0 that lets an application sign people in with an account at another service. It adds the ID token, standard claims, and discovery to the OAuth exchange. client asks for continued access explicitly, and the provider asks the person to agree. A refreshed ID tokenIn OpenID Connect, a signed JWT from the provider, addressed to one client, saying which account authenticated, when, and in answer to which request. It reports a sign-in and is not used to call APIs. may come back later, but it describes the original sign-in, and a successful refresh never shows that the person is present or extends their sessionThe ongoing connection between later requests and an earlier sign-in, so you are not asked for your password on every click. It is often tracked with a cookie holding an unpredictable session identifier..
Asking for offline access
All domains, identifiers and tokens in these examples are fictional.
At 09:04 on 1 October, still signed in, Ava turns on the collage app's year-end collage: every December the app picks her best photos of the year and sends her a preview, long after she has closed her browser. The refresh token grant told a story like this from the OAuthA framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in. side, with the printer's yearly calendar, and noted that a client asks for continued access with the offline_access scope. The collage app is an OpenID Connect relying partyAn application that accepts and relies on a sign-in from another service, the name used in OpenID Connect and for passkeys. SAML calls the same role a service provider., so it asks.
Ava's sign-in at 09:00 asked only for openid profile email. It gave the collage app no access to her photos and no refresh tokenA longer-lived credential that a client sends to the authorization server, never to an API, to get new access tokens without asking the person again., which suited a sign-in. The year-end collage needs something else, so the app sends a separate authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do. request to the return address it uses for photo connections:
https://auth.photos.example/authorize
?response_type=code
&client_id=photo-collage
&redirect_uri=https%3A%2F%2Fcollage.example%2Foauth%2Fcallback
&scope=openid%20photos.read%20offline_access
&prompt=consent
&state=demo-attempt-8
&nonce=demo-nonce-8
&code_challenge=kPeoXcI0Ujq4KQcqIPlQawjpjjUu9V-tXHYDUACSnNM
&code_challenge_method=S256The offline_access scope asks for a refresh tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. that keeps working while Ava is away. OpenID Connect defines it narrowly, as a refresh token that can obtain access to her UserInfo endpointAn OpenID Provider endpoint that returns claims about the signed-in person to a client presenting an access token. Its sub must match the ID token's before the client uses anything it returns. even when she isn't present, but its consent rules speak of offline access to whatever resources are requested. Providers commonly treat it as the request for a refresh token covering the whole grant, and the photo service does: the refresh token it issues here will obtain photos.read access tokens in December. Including openid makes this an OpenID Connect request, so an ID token comes back as well.
prompt=consent asks the photo service to show Ava a consent screen, even though she has approved the collage app before. The specification requires it alongside offline access unless the provider has some other established basis for granting it, and it requires the provider to obtain her consent before returning a refresh token for offline use. An approval she gave earlier, for a sign-in, isn't necessarily enough. An application that can act while she is away deserves a deliberate decision, and the provider should make the long-term access clear:
Photo Collage would like to:
View your photos
Keep this access when you are not using Photo CollageIf the collage app left out prompt=consent and the photo service had no other basis for offline access, the specification tells the provider to ignore the offline_access request rather than refuse it. The authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. would succeed without a refresh token for offline use. A provider's own policy can also withhold refresh tokens from a client. So the app checks what the token response contains, and if no refresh token arrives, it tells Ava now that the year-end collage can't be set up, rather than discovering the problem in December.
Ava approves, and the token response looks familiar:
{
"access_token": "demo-access-token-8",
"token_type": "Bearer",
"expires_in": 600,
"refresh_token": "demo-refresh-token-3",
"scope": "openid photos.read offline_access",
"id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6InBob3Rvcy1ycy0yMDI2LTA5IiwidHlwIjoiSldUIn0..."
}The ID token is shortened here. The collage app validates it as it validated her sign-in, against demo-nonce-8 this time, and records that the connection belongs to user-2048, the photo account she signs in with. The refresh token goes into the connection record that Server-rendered web applications described, tied to account 8812 rather than to the session that created it.
Refreshing in OIDC
On 1 December at 09:00, the year-end collage job sends demo-refresh-token-3 to the token endpointThe authorization server address where clients exchange an authorization code, refresh token, or other grant for tokens, in a direct request rather than through a browser redirect.. The request is exactly the one from The refresh token grant: the grant type, the refresh token and the app's client authentication. OpenID Connect adds nothing to it. The response adds one field:
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{
"access_token": "demo-access-token-9",
"token_type": "Bearer",
"expires_in": 600,
"refresh_token": "demo-refresh-token-4",
"scope": "openid photos.read offline_access",
"id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6InBob3Rvcy1ycy0yMDI2LTA5IiwidHlwIjoiSldUIn0..."
}A provider may leave the ID token out of a refresh response, so the collage app must not depend on getting one. When one is present, OpenID Connect restricts what it may say. Here are the claims of the December token beside those of the ID token from October's authorization:
| Claim | October, from the authorization | December, from the refresh |
|---|---|---|
iss | https://auth.photos.example | The same |
sub | user-2048 | The same |
aud | photo-collage | The same |
iat | 1790845440 (1 October, 09:04:00) | 1796115600 (1 December, 09:00:00) |
exp | 1790845740 (1 October, 09:09:00) | 1796115900 (1 December, 09:05:00) |
auth_time | 1790845185 (1 October, 08:59:45) | The same |
nonce | demo-nonce-8 | Absent |
The identity claims can't move. iss, sub and aud must match the ID token from the original authentication, so a refresh can never produce a token about a different person or for a different client. iat and exp are new, because this is a new token with its own short lifetime.
auth_time doesn't move either, and it matters most. It must still give the time of the original authentication, 08:59:45 on 1 October, not the time of the refresh. Notice that the October value is already earlier than that token's iat. When Ava turned on the year-end collage, the photo service asked for her consent but didn't ask her to authenticate again, because its session from her sign-in four minutes earlier was still running. No one authenticated in December at all. The token is new, but the authentication it describes is two months old.
The nonce is gone. A nonceA random value used for one attempt only. In OpenID Connect, the client sends one in its sign-in request and checks that the same value comes back inside the ID token, showing the token answers this attempt. ties an ID token to the authentication request that asked for it, and in December there was no authentication request, only a back-channel call from the app's server. The specification says a refreshed ID token should not contain one, and if it does, the value must be the original's.
So the collage app checks a refreshed ID token against the connection it already holds, after validating its signature and lifetime as usual. The issuer, subject and audience must be the ones it recorded in October, auth_time must still say 08:59:45 on 1 October, and a nonce, if one appears at all, must be demo-nonce-8. If anything else comes back, the app doesn't use the new token, and it marks the connection for someone to look at. When the response carries no ID token, nothing is wrong: the connection already knows whose it is from the token it validated in October, and the access token is what fetches the photos.
Refresh is not presence
The December refresh proves that this authorization remains usable and that the collage app can authenticate as the client. It doesn't prove that someone is now at a browser, that the provider session is still open, or that the person has just authenticated. A new iat is not a new auth_time.
Ava approves, 1 October
- Who took part
- Ava, her browser, photos
- Person at a browser
- Yes
- iat
- 1 October, 09:04
- auth_time
- 1 October, 08:59:45
- Starts a session
- Could: she is there
Ava was there
Refresh, 1 December
- Who took part
- App server, photos
- Person at a browser
- Not shown
- iat
- 1 December, 09:00
- auth_time
- 1 October, 08:59:45
- Starts a session
- No
The grant is still usable
Session renewed from a refresh
- Who took part
- App server, photos
- Person at a browser
- Whoever has the cookie
- iat
- New
- auth_time
- 1 October, 08:59:45
- Starts a session
- Would, wrongly
The absolute timeout means nothing
A new iat is not a new auth_time.
That makes one shortcut tempting and wrong. Ava's collage app session reaches its absolute deadline on 8 October. An app that wanted to keep her signed in longer could notice the expired session, refresh the year-end connection for account 8812, and treat the new ID token as a new sign-in. The token is genuine and names her, so this looks harmless. But the refresh involved only the app's server and the photo service, never Ava or her browser. Whoever presented the expired cookie, perhaps someone at a library computer she forgot to sign out of, would get a fresh session. The absolute timeout would stop meaning anything, and the account would stay open as long as the refresh token family lasts, which Refresh tokens and rotation set at two years.
So the collage app doesn't renew an expired session from the year-end connection. When Ava's session ends, her next visit starts a new sign-in, with fresh state, nonce and PKCE values. The photo service may answer straight from its own session or ask her to sign in, and the app then applies its own rules about how recent that sign-in must be. Another application might choose a longer session than the collage app does. What none should do is treat a refresh, made by a server or by a browser app, as the person coming back.
The independence runs the other way too. A refresh that fails with invalid_grant means the connection needs Ava to reconnect. It doesn't sign her out of the collage app, any more than signing out of the app cancels the year-end collage. Nor do refresh results reveal her photo service session. Current security guidance allows a provider to revoke refresh tokens when someone signs out of it, while offline access exists so that a grant can outlast that person's sessions there. Which the photo service does is its own policy.
When the collage app genuinely needs to know whether Ava is present, the reliable way to find out is to send her browser to the photo service with an authentication request and see what comes back.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Request offline access and compare refreshed ID tokensAsk separately for photos.read with offline_access and prompt=consent, refresh, compare the original and refreshed ID tokens claim by claim, then show that a refresh is not proof that anyone is present.