Access tokens: limit API permissions and handle them safely
Learn what an OAuth access token does, how to constrain its audience and authority, and what to do if it may have leaked.
Access tokens: limit API permissions and handle them safely
An access token is a credential issued by an authorization server so a client can call a protected API or resource. It avoids sending a user's password to every API, but anyone who can use a bearer token may act with its granted authority. Limit the token's recipient, operations, delivery path, and lifetime, and protect it like a secret.
An access token is not necessarily a JWT. OAuth 2.0 does not prescribe its internal format: it may be an opaque string understood by the authorization server or a JWT with claims. The API must follow the issuer's defined validation method rather than guessing from the string. The client presents the token to the resource server, which checks validity and whether the requested operation is authorized. An ID token reports authentication to a client; a refresh token is used to obtain new access tokens. Neither has the access token's role.
Send the token in the Authorization header
For the Bearer method in RFC 6750, send the token over TLS in the Authorization header, for example Authorization: Bearer <access-token>. Avoid putting it in a URL query: URLs may appear in server logs, browser history, proxies, and Referer headers. Keep the raw value out of application logs, error tracking, analytics, and browser history. Anyone holding a bearer token can use it without proving possession of a separate key.
Constrain what the token can do
Issue only what the client needs. Check that the token is limited to the intended API (audience), the necessary operations (scope), and the smallest useful record, project, or tenant set. Set an expiry that fits the risk, and consider sender-constrained tokens when the architecture supports them. A scope such as read does not automatically permit reading every record: the resource server must also enforce ownership, tenant boundaries, account status, and its own policy. RFC 9700 recommends audience and privilege restriction; deployment and performance constraints affect which sender-constraint design is practical.
If a token expires or may have leaked
Validate it using the issuer's method. For JWTs, use the agreed profile; for opaque tokens, use the issuer's introspection or validation mechanism.
Check authorization separately: reject when scope, resource, tenant, or requested HTTP operation exceeds policy, even if the token itself is valid.
Check TLS termination, proxies, logs, browser storage, and error systems for exposed copies. Restrict access to affected log copies and handle them under retention policy.
Revoke the token or related grant using the authorization server's supported process. Revocation may not propagate immediately, and some deployments do not support access-token revocation; temporarily block the affected resource if remaining validity creates risk.
Correct excessive scope, long lifetime, broad audience, or unsafe delivery before issuing a least-privilege replacement. Consider sender constraint where supported.
Revocation behavior depends on the issuer and deployment. A self-contained token may remain usable until expiry if resource servers do not check revocation status. The success criterion is not merely that a token was issued: only intended operations and resources should work, and other APIs or an attacker should be denied.
Sources
[RFC 6749: OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749.html)
[RFC 6750: OAuth 2.0 Bearer Token Usage](https://www.rfc-editor.org/rfc/rfc6750.html)
[RFC 7009: OAuth 2.0 Token Revocation](https://www.rfc-editor.org/rfc/rfc7009.html)
[RFC 9068: JWT Profile for OAuth 2.0 Access Tokens](https://www.rfc-editor.org/rfc/rfc9068.html)
[RFC 9700: Best Current Practice for OAuth 2.0 Security](https://www.rfc-editor.org/rfc/rfc9700.html)