OAuth 2.0 access-token expiration and least-privilege scope enforcement
0 reputation · 10 Jul 2022, 22:56 UTC
0 reputation · 10 Jul 2022, 22:56 UTC
OAuth 2.0 access tokens carry both an expiration timestamp (exp claim) and a set of granted scopes. Resource servers must reject expired tokens, but the specification leaves open how servers should handle tokens that are still valid yet request scopes exceeding the client's current least-privilege assignment.
When a token's scopes are broader than the client's current role permits—due to role changes after token issuance—servers face a decision: reject the request immediately, downgrade the effective scopes to the intersection, or rely on the token's original authorization. RFC 6749 and RFC 7662 do not mandate a specific approach, and implementations differ.
This affects systems that rotate roles frequently or enforce just-in-time access, where a token issued under a privileged role may outlive the role assignment.
exp). When a client's roles or permissions are revoked after a token is issued, the specification does not mandate that the RS should 'downgrade' the scopes or reject the token early.
Most major implementations—including Keycloak, Azure AD, and Spring Authorization Server—follow a 'stateless' approach for JWTs. If the token is cryptographically valid and has not expired, the RS trusts the scopes contained within the payload. These systems do not typically cross-reference with the Identity Provider (IdP) for every request unless explicitly configured to do so.
scope field reflects what was granted at the time of authorization.To align tokens with current permissions without significantly shortening token lifetimes, consider these architectural patterns:
jti (JWT IDs) to a shared cache (like Redis). The RS checks this 'blacklist' before processing requests.Diagnostic Note: Are your resource servers using stateless JWTs (local validation) or opaque tokens (introspection-based)? This determines whether you must implement custom revocation logic or switch architectures.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.