← blog · November 16, 2026

Token Lifetimes and Logout in OIDC: Short Access Tokens, Refresh Token Rotation, Concurrent Refresh and Back-Channel Logout

The hours after login: why access tokens should be short, why refresh tokens belong outside the browser, why users get logged out at random once rotation is on, and how to end the provider session on logout.

In an application that signs users in with OIDC, most mistakes are not made at login. They are made in the hours after it. How long should the access token live, where should the refresh token sit, and what exactly should end when the user clicks "log out"? Wrong answers to these questions come back either as security holes or as bugs that log users out at random moments and are hard to reproduce. This post lays out how to design token lifetimes and logout correctly from the start.

Separate the layers first: there are three sessions

A typical OIDC setup runs three independent lifetimes at once:

  1. The identity provider session. Once the user signs in at the provider, the provider sets its own cookie. This is where single sign-on comes from: moving to another application does not ask for a password.
  2. The application's own session. After exchanging the code for tokens at the callback, the application usually opens its own session cookie.
  3. Token lifetimes. The access token, the refresh token and the ID token each have their own expiry.

Most bugs come from treating these as one thing. The classic case: on logout the application deletes only its own cookie. When the user clicks "sign in" again, the provider session is still alive, so they are let straight back in without a password. To the user the logout button is broken; on a shared computer it is a real security problem.

Access tokens: keep them short, do not rely on revocation

If the access token is a signed JWT, the resource server accepts it by checking the signature and exp without asking the provider. That is fast, but it has a cost: there is no standard way to take back an issued JWT. Disable the user, reset their password, and the token still works until it expires.

You have two options:

  • Short-lived JWTs. Somewhere between 5 and 15 minutes is a common choice. The revocation delay is at most that long. This is the right default for most applications.
  • Opaque tokens with introspection (RFC 7662). The resource server asks the provider about the token on every request, or with a short cache. Revocation is immediate, but every request now depends on the provider, and when the provider slows down the whole API slows down.

My position: start with short-lived JWTs. Move to introspection only on surfaces that truly need instant revocation, such as money movement or admin actions. Letting access tokens live for an hour or a day and saying "we will revoke if needed" means building a system you cannot actually revoke in.

Do not forget clock skew during validation. A few seconds of drift between servers is enough for a freshly minted token to fail its iat or nbf check. Most libraries offer a leeway setting; 30 to 60 seconds is plenty. A larger leeway gives back what the short lifetime bought you.

Refresh tokens: this is the valuable one

With short access tokens, the refresh token is what keeps the user signed in. It is also what an attacker actually wants, because it can mint new access tokens for weeks. Two decisions matter most.

Where it lives. In a browser single page application, putting the refresh token in localStorage means any script that makes it onto the page can read it. Current guidance is the Backend for Frontend pattern: tokens stay on the server, and the browser only carries a session cookie marked HttpOnly, Secure and SameSite. This layer forwards API calls and attaches the token. It is one more component, but having no tokens in the browser at all shrinks the attack surface dramatically.

Rotation. The OAuth security best current practice (RFC 9700) asks that refresh tokens for public clients (browser, mobile, desktop) be either sender-constrained (DPoP, RFC 9449, or mTLS) or rotated on every use. With rotation, each refresh returns a new refresh token and invalidates the old one. If the provider sees an old token being reused, it treats this as a sign of theft and revokes the whole chain derived from it.

Rotation's own trap: concurrent refresh

Almost every team that enables rotation hits the same problem: users get logged out occasionally, with no obvious pattern. The cause is usually this. The access token has expired, the application fires three API calls at once, all three get a 401, and all three try to refresh with the same refresh token. The first one wins and rotates the token. The other two use what is now an old token, the provider sees reuse and revokes the chain. The same happens with several tabs open.

The fix lives on both sides.

On the client, collapse refreshes into a single flight: only one refresh request goes out at a time, and everyone else waits for its result.

let refreshing: Promise<string> | null = null;

async function getAccessToken(): Promise<string> {
  if (!isExpired(current)) return current.accessToken;
  if (!refreshing) {
    refreshing = refreshTokens().finally(() => { refreshing = null; });
  }
  return refreshing;
}

That is not enough across tabs, because each tab has its own memory. In the browser, the Web Locks API (navigator.locks.request) gives you a single lock across tabs. With a Backend for Frontend the problem moves to the server and is solved with a per-session lock there, which is one more reason to use that pattern.

On the provider side, if your product supports it, allow a reuse window of a few seconds for the previous token. It rescues a duplicated request that arrived late over the network, but keep it short or rotation stops protecting anything.

Logout: three mechanisms that do different jobs

RP-Initiated Logout. After closing its own session, the application redirects the user to the end_session_endpoint from the provider's discovery document:

GET {end_session_endpoint}
  ?id_token_hint={id_token received at login}
  &post_logout_redirect_uri=https://app.example.com/logged-out
  &state={random value}

The provider ends its session and sends the user back. The post_logout_redirect_uri must be registered on the client in advance, or the provider will refuse the redirect. You also need to keep the ID token from login. Many teams discard it after validation and have no id_token_hint left at logout time.

Back-Channel Logout. When the user logs out from another application or directly at the provider, the provider sends a server-to-server POST to your application. The body contains a signed JWT called logout_token. When validating it, check the signature, iss, aud and iat, that the events claim contains the key http://schemas.openid.net/event/backchannel-logout, that at least one of sid or sub is present, and that there is no nonce. Once it passes, end the matching local sessions and return 200.

The step people skip: to know which local session to end, you must have stored the sid from the ID token in your own session record at login. If sessions live only in a signed cookie with nothing on the server, the back-channel call arrives and there is nothing to close. If you want this mechanism, pick your session store accordingly.

Front-Channel Logout. The provider's logout page loads each application's logout URL in a hidden iframe. Because browsers now restrict third-party cookies, the request inside the iframe often does not carry the application's cookie, so logout silently does nothing. Do not rely on it in a new setup; prefer back-channel logout.

Other common mistakes

  • Requesting offline_access by default. A refresh token obtained with this scope keeps living after the provider session ends. The user believes they are logged out everywhere while tokens can still be minted in the background. Grant it only to clients that genuinely need offline access.
  • No absolute cap on refresh tokens. Rotation hands out a fresh token every time; without a maximum, a session that is used continuously lives forever. Define a total lifetime in addition to the idle timeout.
  • Not revoking tokens on password change. Users change their password because they suspect their account was taken. If refresh tokens are not revoked, the attacker stays in.
  • Sending the ID token to an API as if it were an access token. The audience (aud) of an ID token is the client itself, not the API. APIs should accept only access tokens issued for them.

When you do not need all this

If you have a single server-rendered application, no need for SSO and no other clients calling your API, using OIDC only at login and continuing with a classic server session is perfectly fine. You never store the tokens after login, so rotation and single-flight refresh do not apply. Even then, redirect to the provider on logout, or the "logout does not work" problem from the first section shows up exactly as described.

The short version: keep access tokens short, keep refresh tokens out of the browser and rotate them, collapse refreshes into a single flight, end the provider session on logout, and record the sid with your session so you can honour logouts that start somewhere else.