Bearer tokens: send them safely in HTTP requests and distinguish response errors
A bearer token is a credential that lets whoever holds it access a protected resource without separate cryptographic proof. In OAuth 2.0 Bearer usage, clients usually send an access token in the Authorization: Bearer <access-token header. Because someone else can use a leaked token, send it over HTTPS, keep it out of URLs, and limit its privileges and intended audience.
A bearer token is a credential that lets whoever holds it access a protected resource without separate cryptographic proof. In OAuth 2.0 Bearer usage, clients usually send an access token in the Authorization: Bearer <access-token> header. Because someone else can use a leaked token, send it over HTTPS, keep it out of URLs, and limit its privileges and intended audience.
Understand the token and the Bearer scheme
An access token is a string issued by an authorization server to a client. The resource server validates it to decide whether to accept a request. “Bearer” describes how possession works: the caller presents the token and does not separately prove ownership of a cryptographic key. That differs from tokens that require a proof-of-possession signature.
Do not confuse an access token with an ID token or API key. An ID token gives a client authentication information about a signed-in user; an access token authorizes API access at a resource server. API keys vary by provider and may only identify usage or billing. Check the issuer’s documentation for the token’s purpose and audience.
Use the standard request header
RFC 6750 recommends sending a Bearer access token in the HTTP Authorization header. This example uses a placeholder token. Do not paste a real token into command history, screen shares, or logs.
GET /v1/orders HTTP/1.1
Host: api.example.test
Authorization: Bearer <access-token>
Accept: application/jsonClients must use HTTPS when requesting protected resources and validate the server’s TLS certificate chain. RFC 6750 requires TLS for Bearer-token requests. A plain HTTP request could let someone observing the network steal the token and access the protected resource.
Do not put the token in a URL query. URLs can be retained in browser history, server or proxy access logs, analytics systems, or Referer information sent to another page. RFC 6750 says the query method has security weaknesses, including a high likelihood that the URL will be logged, and should not be used unless header or request-body transmission is impossible. Also, do not send the same token through multiple methods in one request. For ordinary API calls, use the header.
Grant only needed permissions and lifetime
An access token reflects authorization policy such as scope, lifetime, and intended resource at issuance. The OAuth security best current practice, RFC 9700, recommends limiting token privileges to what the application and use case need and restricting the intended resource server where possible. Do not reuse a token for a broader set of APIs or actions than necessary; implement expiry and revocation according to the issuer’s documentation.
Do not infer a token’s contents just because it is a string. An opaque token may not be designed for the client to read. Even if a token looks like a JWT, it is not trustworthy until the resource server validates the signature, issuer, audience, expiry, and other required claims. Client code should obtain the token from its issuer, send it as documented, then renew or reauthenticate in response to the provider’s error contract.
Handle 401 and 403 differently
The OAuth Bearer specification uses invalid_token and typically 401 Unauthorized when a token is expired, revoked, malformed, or otherwise invalid. A client may request a new token and retry in a controlled way; it should not retry indefinitely, and should surface an authentication failure if renewal fails. By contrast, insufficient_scope means the token is valid but lacks the privileges required for the request, usually resulting in 403 Forbidden. Repeating the same request with the same token will not add permissions.
Providers may implement response bodies and headers differently, so follow the API’s error contract. Keep token strings out of error messages, telemetry, and request dumps. For diagnosis, record a request ID and error code without the credential.
Configuration checklist
Do you send the token in `Authorization: Bearer …` over HTTPS and validate the server certificate?
Is the token kept out of URLs, browser history, public client bundles, command history, proxy logs, and application logs?
Does each request use a token with the needed audience and minimum scope, without duplicating the transmission method?
Do you handle `401 invalid_token` through renewal or reauthentication and `403 insufficient_scope` as a permissions problem?
Do expiry, revocation, reissuance, and log redaction follow the issuer’s and service’s policies?
Bearer tokens are convenient HTTP credentials, but possession alone is enough to use them, so preventing disclosure is central. Combine header-based transmission, TLS, minimum privileges and audience, limited exposure, and explicit expiry and error handling.
Sources
[RFC 6750: OAuth 2.0 Bearer Token Usage](https://www.rfc-editor.org/rfc/rfc6750.html)
[RFC 9700: OAuth 2.0 Security Best Current Practice](https://www.rfc-editor.org/rfc/rfc9700.html)
[RFC 9110: HTTP Semantics, Authorization field](https://www.rfc-editor.org/rfc/rfc9110.html)