Token expiration

Also known as: access token lifetime

On this page 7

Token expiration is the point in time after which a security token, such as an OAuth 2.0 access token, an ID token or a session cookie, is no longer accepted by the systems that rely on it. In identity & access management, the access token lifetime limits how long a credential remains useful, which caps the damage of a stolen token and forces periodic revalidation of the user and the granted permissions.

Expiration is one of the most important controls in Cybersecurity token design because bearer tokens grant access to whoever presents them. A short lifetime shrinks the window of misuse, while refresh mechanisms preserve a smooth user experience without asking for a password every few minutes.

How token expiration is enforced

Token expiration is enforced either by reading a timestamp inside the token or by checking a server-side record. Self-contained tokens such as JSON Web Tokens carry an exp claim, expressed as seconds since the Unix epoch, and every resource server compares it with its own clock before accepting the request.

Reference tokens, also called opaque tokens, contain no readable data. The resource server sends them to the authorization server through token introspection, defined in RFC 7662, and the response states whether the token is still active. This design allows immediate revocation but adds a network call to every validation.

The following table lists the JWT claims that govern a token’s time window and how validators use them.

ClaimMeaningValidator behavior
expExpiration timeReject the token at or after this moment
nbfNot beforeReject the token before this moment
iatIssued atUsed to compute age and enforce maximum lifetime
auth_timeTime of user authenticationTriggers reauthentication when too old
Time-related claims in a JSON Web Token

Because distributed servers rarely share a perfect clock, validators usually allow a clock skew tolerance of about 30 seconds to five minutes. A tolerance that is too generous quietly extends every token’s real lifetime.

Typical lifetimes for different token types

Different token types carry different lifetimes because they protect different assets and face different exposure. There is no universal standard value; the figures below reflect common practice and depend on risk tolerance, client type and regulatory context.

Token typeTypical lifetimeMain reason
Access token5 to 60 minutesBearer credential sent with every request
ID token5 to 60 minutesProves a recent login to the client
Refresh tokenHours to 90 daysStored securely and used rarely
Authorization codeUnder 10 minutesSingle-use exchange step in OAuth 2.0
Session cookieIdle 15 to 30 minutes, absolute 8 to 24 hoursBalances security with convenience
SAML assertionUsually under 5 minutesConsumed once at login
Common lifetime ranges by token type

Sessions and refresh tokens typically combine an idle timeout, which ends the session after inactivity, with an absolute timeout, which ends it regardless of activity. The absolute limit guarantees that even an actively abused credential eventually stops working.

Expiration, revocation and refresh compared

Expiration, revocation and refresh are complementary mechanisms that together define when a token stops being valid. Expiration is passive and predictable, revocation is an active decision to end validity early, and refresh replaces an expiring token with a new one.

MechanismTriggerStrengthWeakness
ExpirationFixed time passesNo server lookup for JWTsStolen token works until expiry
RevocationLogout, compromise or policy changeEnds access immediatelyNeeds introspection or deny lists
RefreshAccess token near expiryKeeps users signed inRefresh token becomes a prime target
Credential rotationScheduled key or secret changeInvalidates all tokens signed with old keysDisruptive if done abruptly
Mechanisms that control token validity

Refresh token rotation strengthens the refresh model: each use returns a new refresh token and invalidates the old one. If an attacker replays a used refresh token, the authorization server detects the reuse and can revoke the entire token family, which is a recommended pattern for public clients such as single-page applications.

Choosing an appropriate token lifetime

Choosing a token lifetime means balancing exposure against cost: shorter tokens limit misuse, but they increase traffic to the identity provider and the frequency of refresh failures. The right value depends on the sensitivity of the resource, how tokens are stored, and whether revocation is available in real time.

ScenarioRecommended approachReason
Banking or administrative APIsAccess tokens of 5 to 10 minutesHigh impact of a stolen token
Internal microservicesShort JWTs with automated renewalAvoids introspection latency
Mobile applicationShort access tokens, rotating refresh tokensDevice loss is a realistic risk
Browser single-page applicationShort tokens and backend-held refresh tokensBrowser storage is exposed to script
Long-running batch jobsClient credentials with automatic re-requestAvoids long-lived static tokens
Lifetime decisions for common scenarios

Sensitive operations often require step-up authentication regardless of token age. A policy might demand that auth_time be no older than 15 minutes before allowing a payment, even when the access token itself is still valid.

Common mistakes with token expiration

Most failures related to token expiration come from implementation shortcuts rather than from the standards themselves. The following mistakes appear repeatedly in security reviews.

  • Not validating `exp` at all, which turns every issued token into a permanent credential.
  • Very long access token lifetimes, such as several days, chosen to avoid building a refresh flow.
  • Non-expiring refresh tokens without rotation, idle limits or binding to a client.
  • Assuming logout revokes JWTs: deleting a cookie does not invalidate a self-contained token already copied by an attacker.
  • Ignoring clock drift, which causes sporadic rejections or silently extends validity.

Binding tokens to a client, for example through mutual TLS or DPoP proof-of-possession, reduces the value of a stolen token beyond what expiration alone can achieve, because the thief also needs the client’s private key.

In everyday language

A token is like a wristband at a festival. It proves you paid, so staff let you in without checking your ticket each time. Token expiration means the wristband is only valid for a set time, perhaps one day.

If someone steals your wristband, they can use it only until it expires. To stay inside longer, you show your ticket again and receive a fresh band. Short validity limits the harm of theft, while the quick renewal keeps the experience convenient.

Seen in the real world

An online retailer runs a single-page web store backed by an OAuth 2.0 authorization server. Originally, access tokens lasted 24 hours and were kept in browser storage. A security review shows that a cross-site scripting flaw could let an attacker copy a token and act as the customer for a full day.

The team reduces the access token lifetime to 10 minutes, moves refresh tokens to a backend component that holds them in a secure, HTTP-only cookie, and enables refresh token rotation with reuse detection. Checkout additionally requires a login within the last 15 minutes. Months later, a test token captured during a penetration exercise stops working after ten minutes, and its replayed refresh token revokes the whole session family, confirming that the new design limits real exposure.