An access token is issued after successful authorisation — most often through OAuth 2.0 — and is short-lived, often under an hour. The client sends it in the Authorization header, and the server checks it and processes the request. This way the application works with an API on the user’s behalf without ever learning their password.
How it works
| Step | What happens |
|---|---|
| Authorisation | the client goes through the authorisation server, for example via the authorization code flow |
| Issue | the authorisation server returns an access token and usually a refresh token |
| Request | the client sends a request to the API with a header like Authorization: Bearer <token> |
| Validation | the resource server checks the token and what it allows, and decides whether to process the request |
| Renewal | when the token expires, the client obtains a new one using the refresh token, without asking the user |
Token formats
There is no single format: OAuth 2.0 describes the token as a string that either denotes an identifier the server can look the rights up by, or carries them inside in a verifiable form; to the client the string is usually opaque. In the first case it is a random string, and the resource server asks the authorisation server what stands behind it. In the second it is usually a JWT: the data is embedded in the token and signed, and the resource server verifies the signature locally, without extra requests.
The most common type is the bearer token: whoever presents the string gets access, with no proof of key possession. That is why tokens are sent only over HTTPS, issued for a short time and with a limited scope.
How to handle tokens
- send the token only over HTTPS: an intercepted token gives an attacker the same access
- issue short-lived tokens — RFC 6750 recommends an hour or less
- limit the scope: a token for reading a calendar must not allow sending email
- do not store it in cookies that are transmitted in the clear
Sources
the term is written from these pagesVerified 9 Nov