Authentication looks simple from the outside: a sign-in page, a sign-out button. Underneath, it is a stack of specifications written over more than a decade, identity providers that each made their own choices, and best practices that changed along the way. I have been building apps that deal with authentication, both at work and in personal projects. Whenever I asked an AI assistant about authentication and authorization, the answers were often confusing and sometimes misleading. They changed from one question to the next, and explanations that sounded confident fell apart as soon as I looked closer. So in this post I lean on the specifications themselves, and quote them wherever I can.
The earlier posts in this series covered how a sign-in is protected: state, PKCE, the nonce, exact redirect URIs. This post is about what the app receives after the sign-in: an access token and a refresh token. I want to answer three questions that confused me for a long time. How long should each token live? Who decides when a user is signed out? And what is offline_access, a value I had been putting in my apps' configuration without really understanding it?
The base for this post is the IETF's current guide for web apps: RFC 10017, *OAuth 2.0 for Browser-Based Applications*, published in August 2026 as Best Current Practice 212. Every quote marked "RFC 10017" comes from it: https://www.rfc-editor.org/rfc/rfc10017
A few terms first
An identity provider is the server where users sign in: Google, Microsoft, Keycloak, or one your company runs. They send the user to the identity provider, and they get tokens back.
Two specifications define how that works, and they are easy to mix up:
- OAuth 2.0 (RFC 6749) is about authorization: how an app gets an access token that lets it call an API on the user's behalf. With OAuth alone, the app gets permission to call the API, but it doesn't learn who the user is. OAuth calls the identity provider the authorization server.
- OpenID Connect is about authentication. It describes itself as "a simple identity layer on top of the OAuth 2.0 protocol", and its main addition is the id_token, which tells the app who signed in. OpenID Connect also defines the
offline_accessscope discussed below, and, in companion specifications, how users sign out.
In practice, signing in to a modern app uses both: OpenID Connect to know who you are, OAuth to get the tokens for the API. In this post, "identity provider" means the server that does both.
IdentityServer is a .NET framework for building your own identity provider. Version 4 is open source; its successor is the commercial Duende IdentityServer. IdentityServer 4 is no longer supported: its support ended in December 2022, and its repository is now archived. I still use it as a reference in this post because it keeps running in existing systems, including the one I work with, either directly or through community forks such as IdentityServer8.
A scope is a word the app puts in the sign-in request to say what it wants, for example openid profile email.
Where the confusion came from
At work we run an identity provider built on IdentityServer 4. Its documentation explains how an app gets a refresh token:
"Since this is a privileged operation, the clients needs to be explicitly authorized to be able to use refresh tokens by setting the
AllowOfflineAccessproperty totrue.""You can request a refresh token by adding a scope called
offline_accessto the scope parameter list of the authorize request."(Duende IdentityServer documentation, Refreshing a Token: https://docs.duendesoftware.com/identityserver/tokens/refresh/)
So every web app that needed a refresh token asked for the offline_access scope. These apps are used in a browser, with a person in front of the screen. Nothing about them is offline. That raised two questions I couldn't answer: why is it called "offline", and when the user signs out, should the app keep working with its refresh token?
To answer them, we first need to separate two things that are easy to mix up: the identity provider's session and the app's tokens.
Two sessions, not one
When you sign in to an app through an identity provider, two separate things are created.
The first is the identity provider's session. The provider stores a cookie in your browser, on its own domain. While that cookie lives, its sign-in page lets you through without asking for your password again. That is what single sign-on means: you sign in once, and the other apps that use the same provider let you in. OpenID Connect's sign-out specifications give this session an id, called sid.
The second is the app's tokens. After the sign-in, the app receives an access token and, usually, a refresh token. It also receives an id_token, which says who signed in and can carry the sid of the provider session it came from.
The important point is that neither token depends on the provider's cookie. The API validates the access token on its own, without asking the provider about its session. The refresh token is exchanged in a call between the app's server and the provider, with no browser involved. So the tokens can keep working after the provider's session has ended. Whether they should is a decision, and that decision is what this post is about.
The access token: short and narrow
The access token is what the app sends to its API with each request. It is a bearer token: whoever holds it can use it, just like cash. If someone steals it, they can call the API as you until it expires. RFC 10017 gives this advice:
"The recommended defensive strategy to decrease the risk associated with compromised access tokens is to reduce the scope and lifetime of the token." (RFC 10017, §5.1.1)
In practice, that means access tokens should last minutes, not days, and allow only what the app needs. A short lifetime creates a new problem, though. A few minutes later the user is still using the app, and the app needs a new access token without sending the user back to the sign-in page. That is the job of the refresh token.
The refresh token: renewing without the user
A refresh token is exchanged at the identity provider for a new access token. The user doesn't see this happen, and doesn't have to type anything. Because a refresh token is powerful, RFC 10017 sets rules for the identity provider that issues it. They appear in its section on apps that run entirely in the browser (§6.3.2.3), where the risk is highest.
First, it must not live forever. The provider "MUST either set a maximum lifetime on refresh tokens OR expire if the refresh token has not been used within some amount of time."
Second, it must be protected against copying. The provider "MUST either rotate refresh tokens on each use OR use sender-constrained refresh tokens". Rotation means every refresh returns a new refresh token and retires the old one. If the old one is ever used again, someone must have copied it, and the provider can cancel the whole chain. The RFC calls rotation "a detection and correction mechanism" (§5.1.1). Sender-constrained tokens are the alternative: they only work together with a private key that the app holds.
Third, rotation must not stretch the lifetime. A new refresh token must not last "beyond the lifetime of the initial refresh token."
To give a sense of scale, the RFC's own example pairs an access token of 10 minutes with "a refresh token that lasts 8 hours."
Which session should the refresh token follow?
This is the sentence that settled the question for me:
"Authorization servers SHOULD link the lifetime of the refresh token to the user's authenticated session with the authorization server." (RFC 10017, §6.3.2.3)
The RFC also explains why:
"Doing so ensures that when a user logs out, previously issued refresh tokens to browser-based applications become invalid, mimicking a single-logout scenario." (RFC 10017, §6.3.2.3)
In other words, the identity provider's session decides. When it ends, the refresh tokens issued under it should stop working.
That alone doesn't sign the other apps out at once. An app only finds out when it tries to refresh, so it keeps working until its current access token expires. To sign the other apps out right away, the identity provider can notify each of them directly, server to server, using OpenID Connect Back-Channel Logout. Even then, an access token that was already issued stays valid until it expires: one more reason to keep access tokens short. This sentence is in the same section on apps that run entirely in the browser, but I think the reasoning applies to any web app that a person uses in a browser.
This matches what I see with Google in my own browser. When I sign out of Google in one browser, the other Google sites in that browser are signed out too, but my phone and my other browsers stay signed in. Each browser has its own provider session, with its own sid. A private window counts as another browser, which is why it asks for the password again.
Online and offline refresh tokens
This is the heart of the confusion, so let's go slowly.
The difference between "online" and "offline" is not whether the app has a refresh token. Both kinds of app use one, in exactly the same way: every few minutes, the app's server trades it for a new access token. The difference is what happens to the refresh token when the user's session at the identity provider ends.
- An online refresh token is tied to that session. When the user signs out at the identity provider, or the session expires, the next refresh fails, and the app is signed out too.
- An offline refresh token is not tied to that session. It keeps working until its own lifetime runs out or someone revokes it, whether the user is still signed in at the identity provider or not.
An example makes it concrete. In the morning you sign in to three apps through the same identity provider. App A and App C are dashboards you use in your browser. App B is a service that copies your new files to a backup every night.
In the evening, you click "Sign out" in App A. App A ends its own session right away and sends your browser to the identity provider, which ends its session too.
- App C is still open in another tab. A few minutes later, it tries to refresh. Its refresh token was online, so the refresh fails and App C is signed out as well. That is what you wanted: you signed out.
- At three in the morning, App B tries to refresh. Its refresh token was offline, so the refresh works and the backup runs. That is also what you wanted: the backup's whole job is to work while you are not there.
Now swap them. If App C had an offline token, it would stay signed in on that browser after you signed out, and anyone who sat down at your computer could keep using it. If App B had an online token, the backup would stop the first night you signed out.
So the rule of thumb is simple. An app that a person uses should get an online refresh token, which is what RFC 10017 asks for when it says the refresh token's lifetime should be linked to the user's session at the identity provider. An app that has to work while nobody is signed in needs an offline one.
Where the name comes from
offline_access comes from OpenID Connect, not from OAuth. OpenID Connect Core, §11 Offline Access, defines it as a scope that "requests that an OAuth 2.0 Refresh Token be issued that can be used to obtain an Access Token" to reach the user's data while the user is not logged in at the identity provider. So "offline" has nothing to do with the network. It means "the user is not signed in at the identity provider anymore".
Google uses the same word in its own OAuth API. Its authorization request has an access_type parameter with two values, online (the default) and offline, and Google's documentation says to choose offline "if your application needs to refresh access tokens when the user is not present at the browser." (Google Identity, Using OAuth 2.0 for Web Server Applications: https://developers.google.com/identity/protocols/oauth2/web-server)
Because an offline token lets an app act for you while you are away, OpenID Connect normally requires the identity provider to ask the user for consent, and it adds: "A previously saved user consent is not always sufficient to grant offline access." (OIDC Core, §11)
RFC 10017 does not mention offline_access at all. For web apps, the only refresh token it describes is the online kind.
Where IdentityServer 4 fits
OpenID Connect does not require offline_access for every refresh token: §11 ends by saying that refresh tokens are not limited to the offline case. So an identity provider can offer both kinds, and some do.
Keycloak, an open-source identity provider, offers both. ("Online" is my word for it; Keycloak simply says "refresh token".) A normal sign-in gets an online refresh token, tied to the user's session. Asking for offline_access gets what Keycloak calls an offline token, which, in its documentation, "is not subject to the SSO Session Idle timeout and SSO Session Max lifespan" and "is valid after a user logout or server restart".
Auth0, a hosted identity provider, explains the same split in its community forum: an app can refresh tokens without offline_access as long as the user still has an active session at the provider.
IdentityServer 4 offers only one kind. As quoted at the start, an app gets a refresh token only by asking for offline_access. By default, that token is not tied to the user's session: signing out doesn't touch it. IdentityServer 4 does record which session each refresh token came from, though, and offers a method that the sign-out page can call, RevokeTokensForCurrentSessionAsync, which deletes every refresh token of the current session. Nothing equivalent happens when the session simply expires.
That is the whole mess. With IdentityServer 4, App A, the dashboard, can only get the kind of refresh token that App B, the backup, needs. Every web app ends up with an offline token: a token that outlives the user's session at the identity provider. That is exactly what RFC 10017 advises against, unless the sign-out page calls RevokeTokensForCurrentSessionAsync.
Why not skip refresh tokens?
My first idea was to drop refresh tokens altogether and simply issue a new access token every few minutes. The trouble is how the app would get that new token. Without a refresh token, the only way is to send the browser back to the provider's sign-in page with prompt=none, a parameter that asks the provider to answer silently. It works only while the provider's cookie lives.
Apps that run entirely in the browser used to do this inside a hidden iframe. Browsers now block the third-party cookies that this trick needs, and RFC 10017 draws the conclusion:
"in light of the impact of third-party cookie-blocking mechanisms, the use of refresh tokens has become significantly more attractive." (RFC 10017, §6.3.2.3)
So the refresh token is not the problem. It is simply the way to renew an access token without the browser. The real question is how long the refresh token lives, and that is what offline_access changes.
What we are changing
Putting all of this together, this is the model I chose for my own apps.
The identity provider's session decides, and refresh tokens are tied to its sid. When the user signs out of an app, the app sends the browser to the provider's sign-out page, together with the id_token. That flow is defined by OpenID Connect RP-Initiated Logout. The provider then ends its session and revokes every refresh token issued under that sid. Each app's next refresh fails, and the app ends its own session.
When the provider's session expires without a sign-out, the same revocation should happen. My own identity provider revokes at sign-out but not yet at expiry. IdentityServer 4 can revoke at sign-out if the sign-out page calls RevokeTokensForCurrentSessionAsync, and has nothing for expiry. In both cases, the expiry part still has to be written.
How long the provider session lasts then becomes a product decision: it is how long people stay signed in to every app that uses it.
Finally, offline_access stays available for apps that really work while the user is away, with a consent screen that says so.
The other side of this, how the app's backend holds these tokens for the browser (the BFF pattern), is the subject of the next post.
Takeaways
- Access tokens should be short and narrow (RFC 10017, §5.1.1).
- Refresh tokens need a maximum lifetime, and either rotation or a private key that binds them to the app. Rotation must never stretch their lifetime (RFC 10017, §6.3.2.3).
- For web apps, the refresh token should stop working when the user's session at the identity provider ends (RFC 10017, §6.3.2.3).
-
offline_accessmeans "the user is not logged in at the provider", not "no network". It is meant for apps that work while the user is away. - If your identity provider only issues offline refresh tokens, as IdentityServer 4 does, revoke them by
sidat sign-out and at expiry. Otherwise, signing out doesn't fully sign the user out.
References
- RFC 10017, OAuth 2.0 for Browser-Based Applications (BCP 212), §5.1.1 and §6.3.2.3: https://www.rfc-editor.org/rfc/rfc10017
- RFC 9700, Best Current Practice for OAuth 2.0 Security, §4.14.2.
- OpenID Connect Core 1.0, §11 Offline Access.
- OpenID Connect RP-Initiated Logout 1.0.
- Duende IdentityServer documentation, Refreshing a Token (the old IdentityServer4 documentation now redirects here): https://docs.duendesoftware.com/identityserver/tokens/refresh/
- Duende, IdentityServer4 is public again (the archived repository): https://blog.duendesoftware.com/posts/20250306-identityserver4-public-again
- Keycloak Server Administration Guide, Managing user sessions.
- Auth0 Community, Ask Me Anything: Auth0 Sessions and Refresh Tokens.