OAuth access-token expiration: check expiry and renew safely
Learn how clients track token lifetime, how APIs reject expired tokens, and how to handle renewal failures and clock issues.
OAuth access-token expiration: check expiry and renew safely
Access tokens are not permanent credentials. OAuth clients should use lifetime information from the authorization server, and resource servers must reject expired tokens. Shorter lifetimes can reduce the time a stolen token remains useful, but incorrect expiry handling can repeatedly fail legitimate requests.
Expiration sets the validity boundary
For a JWT, exp is the time boundary after which the token must not be accepted. The RFC 9068 JWT access-token profile requires exp and requires the resource server to check it. Implementations may allow a small clock-skew leeway; RFC 9068 gives a few minutes as a typical upper bound. A large leeway weakens expiry.
Not every OAuth access token is a JWT. Clients cannot read an internal exp from an opaque token; validity depends on authorization-server and resource-server policy, introspection, or provider documentation. Do not infer lifetime from the token’s appearance.
When should a client renew?
OAuth response parameter expires_in gives the access token lifetime in seconds from when the response was generated. RFC 6749 recommends it. If it is omitted, the authorization server should provide expiry another way or document a default. Track expiry using the provider’s response and documentation; do not treat an unknown lifetime as unlimited.
For a hypothetical expires_in: 900, the lifetime is 900 seconds from response generation. Use response receipt as a conservative client-side starting point, plan renewal before the boundary, and avoid waiting until the last moment. Where possible, use a monotonic clock to measure elapsed time rather than trusting a device wall clock. Coordinate refreshes per session so simultaneous failures do not start duplicate renewals.
Store `expires_in` or other expiry information officially provided by the provider.
Calculate a renewal time from issue/receipt time and lifetime; use a monotonic clock where available.
Obtain a new access token only through a valid OAuth flow and only when a usable credential, such as a refresh token, is available. Refresh-token scope and storage follow separate rules.
If renewal is rejected or the refresh token has expired, the user may need to authenticate again. Do not retry forever or keep sending the old token after expiry.
The resource server validates every request and rejects expired tokens. A client timer or decoded `exp` does not replace API validation.
Lifetime affects security and operations
Shorter access-token lifetimes reduce the time a stolen bearer token can be used. Very short lifetimes increase renewal traffic and dependency on the authorization server, so network failures or server outages can cause more requests to fail. RFC 6749 and OAuth security best practice do not define one universal lifetime for every service. Set and verify a policy based on data sensitivity, theft impact, renewal design, availability, and operating cost.
Expiration differs from revocation. Expiration blocks use after a scheduled time; revocation marks a token invalid earlier. Revocation may take time to propagate, and a self-contained JWT may remain usable until exp if the API does not check external state. For immediate access removal, consider whether short lifetime is sufficient or whether introspection or a separate deny policy is needed.
Common errors and recovery
**Treating `expires_in` as minutes:** it is seconds. A unit error renews too early or too late.
**Retrying an expired token:** respond to `invalid_token` with one appropriate renewal attempt; if renewal fails, recover the login or configuration.
**Using the client clock as server truth:** clients can plan renewal, but servers must validate with their own clock and policy.
**Extending lifetime to hide a failure:** first investigate stale caches, clock skew, renewal races, or environment-specific settings. Weaker validation increases exposure time.
Summary
Use the provider’s documented lifetime, renew before expiry, serialize concurrent renewals, and let the resource server validate every request. Treat expiration and revocation as separate controls and prepare a recovery path when renewal fails.
References
[RFC 6749 §5.1 — Token Response and `expires_in`](https://www.rfc-editor.org/rfc/rfc6749.html#section-5.1)
[RFC 7519 §4.1.4 — `exp` Claim](https://www.rfc-editor.org/rfc/rfc7519.html#section-4.1.4)
[RFC 9068 §4 — JWT Access Token Validation](https://www.rfc-editor.org/rfc/rfc9068.html#section-4)
[RFC 9700 — OAuth 2.0 Security Best Current Practice](https://www.rfc-editor.org/rfc/rfc9700.html)