Identity and access Access tokens 3 min read
What is an access token?
An app sends Authorization: Bearer … to an API. What is the API trusting when it accepts that request?
-
The client presents a credential
An authorization server issues an access token after a client obtains a grant. The client presents that token to a resource server, usually in the
Authorizationheader using theBearerscheme.The resource server validates the token according to its design, then decides whether the token permits this request. OAuth defines how clients obtain and use access tokens; the resource server enforces the access rules.
A client sends a request with a bearer access token to an API. The API validates the token and checks whether the requested operation is allowed before returning data.
The API must validate the token and authorize the requested operation. In short The client presents the token; the API decides what it permits.
-
Bearer means possession matters
A bearer token works for whoever presents it. If it leaks from a log, a URL, a browser extension, or a compromised machine, someone else may be able to use it until it expires, is revoked, or otherwise becomes invalid.
Keep it out of URLs and logs, send it only over HTTPS to the intended service, and follow the provider’s storage and renewal guidance.
In short Treat a bearer token like a short-lived password for an API.
-
The token’s format isn’t its permission
Some access tokens are opaque strings that only the issuing service understands. Others are structured, such as JWTs. Either way, the resource server must validate the token and enforce the access it represents.
A token can be valid and still not allow a particular action. The API checks applicable scopes or permissions and may also check the user, resource, tenant, or current policy.
In short A valid token is one input to authorization, not a blanket yes.
What an access token doesn’t prove
An access token is for access to a resource. Its presence does not by itself prove a user’s identity to a client; use an identity protocol such as OpenID Connect when an app needs a sign-in result.
A token also cannot make an insecure client safe. If the client or its storage is compromised, the token may be copied and replayed.
Keep this
An access token is a credential for an API; whoever holds a bearer token may be able to use it.
Send access tokens only to the intended resource server over HTTPS, keep them out of logs and URLs, and grant only the access the client needs. Don’t treat an access token as proof of a user’s identity.- Presented
- The client sends it to the intended API, commonly in an Authorization header.
- Checked
- The API validates the token and the access it represents.
- Sensitive
- A bearer token can be used by anyone who gets a copy.
- Not identity
- The token’s presence alone doesn’t prove who the user is.
Questions worth carrying
Is every access token a JWT?
No. An access token can be an opaque string the server looks up or a structured token such as a JWT. Clients should treat it as a credential and avoid depending on its internal format unless the protocol explicitly allows that.
Does a valid token mean every action is allowed?
No. The resource server still checks whether the token is valid for this API and whether its scope, permissions, subject, and other applicable rules allow the requested action.