What is Token Based Authentication?

Token based authentication is a way for an application to use a token as part of proving or maintaining an authenticated relationship with a service. After an initial authentication or other approved process, a client receives a token and presents it on later requests. The receiving service checks that the token is valid for the intended purpose before acting on the request.
The word “token” covers several different credentials. An access token may permit a client to call an API, while an OpenID Connect ID token conveys authentication information to a relying application. Their meaning and checks depend on the protocol and provider. A token does not automatically prove the identity of a person, and a valid token does not automatically permit every action.
How token based authentication works
Imagine a user signing in to a support portal that needs to call a protected API. A trusted identity or authorisation service checks the relevant credentials and issues a token under the chosen protocol. The client presents an appropriate access token when calling the API. The API checks the token and its access rules before returning data.
The illustration shows a simplified token based flow: a user signs in, a service issues a token, a client sends it securely and the receiving service checks the request.

The client starts a supported authentication or authorisation flow.
The relevant service authenticates the user or client as required by that flow.
If the request is approved, the service issues an appropriate token.
The client presents the token to its intended recipient over a protected connection.
The recipient validates the token and applies its own authorisation rules.
When required, the client obtains a replacement token or asks the user to authenticate again.
Real integrations may involve redirects, consent, client authentication, transaction protection and separate sessions. Do not assume the user sends their password to every API or that all tokens are issued immediately after a password check.
Authentication and authorisation are different
Authentication establishes a claimed identity or verifies a credential. Authorisation decides whether an action is permitted. Token based systems can support both, but the receiving component must understand which token it has and what the token is intended to do.
An access token is normally presented to a resource server to request access to a protected resource. It can represent a grant made on behalf of a user or a client acting on its own behalf. An API should not assume that every access token identifies a human user or treat an arbitrary token as proof of a recent user login.
OpenID Connect adds an identity layer to OAuth 2.0. Its ID token communicates authentication claims to the relying application, which must validate it for that application. It is not a general-purpose API access token. The OpenID Connect Core specification defines the ID token and its validation requirements.
Common token types
Token or credential | Typical purpose | Intended recipient |
|---|---|---|
Access token | Request access to a protected API or resource | The intended resource server |
Refresh token | Obtain replacement tokens where supported | The authorisation server's token endpoint |
ID token | Communicate authentication claims in OpenID Connect | The relying application |
Session identifier | Associate a browser or client with server-managed session state | The application managing the session |
API key | Identify or authenticate an application or account, depending on the provider | The API specified by the provider |
The exact format, lifetime and checks vary. Refresh tokens are sensitive credentials and should not be sent to a resource API in place of access tokens. An API key can also be a bearer credential, but its role is provider-specific. The API key guide explains these differences.
What is a bearer token?
A bearer token can generally be used by anyone who possesses it, without an additional proof of possession, subject to the service's validation and permissions. If an attacker obtains a usable bearer token, they may be able to replay it. Protect it in transit, storage, logs and support workflows.
The OAuth 2.0 bearer token specification, RFC 6750, describes sending bearer access tokens in an HTTP authorisation header and requires TLS for its specified use. Do not put sensitive tokens into URLs where logs, browser history or intermediaries may expose them. Follow current security guidance and the provider's integration documentation.
Some systems use sender-constrained tokens, which require the client to demonstrate possession of associated key material. This can reduce the usefulness of a stolen token, but it requires support on both sides and does not protect against every compromise, particularly if an attacker also controls the client or key.
Are all tokens JWTs?
No. A JSON Web Token, or JWT, is a structured format that can carry claims. Other tokens are opaque: their contents are not intended to be interpreted by the client, and the resource server may validate them through the issuing service or another agreed mechanism.
A readable JWT is not necessarily encrypted. Do not put secrets or unnecessary personal information into claims on the assumption that a signed token hides them. A signature can protect integrity and origin when verified correctly, but it does not by itself decide whether a request should be authorised.
For a JWT, the recipient must enforce the checks required by the relevant profile, such as trusted issuer, intended audience, expiry, accepted algorithms and signature. Depending on the flow, other claims and transaction checks may apply. Use a maintained, correctly configured library and reject tokens intended for a different service.
Token storage and browser security
A token that grants access needs protection wherever it is held. Server applications can use appropriately protected storage and restrict access to processes and administrators. Native and browser applications have different threat models, so use the platform's supported mechanisms and the provider's security guidance rather than copying a generic storage recipe.
Browser storage accessible to JavaScript can expose tokens to malicious scripts if the application has a cross-site scripting flaw. An HttpOnly cookie can prevent JavaScript from reading the cookie directly, but cookies introduce their own considerations, including cross-site request forgery protections, secure attributes and session management. Neither choice removes the need to prevent script injection and secure the whole application.
Avoid placing tokens in source code, public repositories, screenshots, URLs, analytics events or application logs. Use HTTPS for all relevant connections, redact sensitive request data and keep privileges limited. A browser-delivered application cannot reliably keep a shared client secret confidential.
Expiry, refresh and revocation
Access tokens often expire after a configured lifetime. A shorter lifetime can limit how long a stolen token remains usable, but it does not prevent theft or automatically terminate an active session. Token lifetimes should reflect the application's risk and operating requirements rather than a universal number.
Where issued, a refresh token can let the client obtain a new access token without repeating the full interactive flow. Refresh tokens need careful protection because they can enable continued access. The OAuth security best current practice, RFC 9700, requires public-client refresh tokens to be sender-constrained or use rotation for replay detection, under its stated conditions.
Revoking a refresh token, ending an application session, removing an authorisation grant and invalidating an access token are different operations. A locally validated token may remain usable until expiry unless the API has an additional revocation check or another control. Introspection, caches, account status and logout support affect the actual result. Test the provider and application together rather than promising immediate logout everywhere.
Token based authentication and sessions
A session can be maintained using a cookie that contains a session identifier, with the application keeping session information on the server. A token can also carry claims or be used to look up server-side state. The boundary is not simply “tokens are stateless and cookies are stateful”: a cookie is a transport and storage mechanism, while a token is a credential or value whose meaning depends on the design.
Server-managed sessions can support central invalidation, but require the session store and its availability to be managed. Self-contained tokens can reduce some lookups, but complicate immediate revocation and require careful key, lifetime and validation policies. Either design can be secure or insecure depending on implementation.
A practical UK example
Imagine a UK technical support company using a case portal and a monitoring API. This is an illustrative design, not a tested deployment or a claim about a named product.
An engineer signs in through the company's identity provider. The portal uses the supported flow to obtain an access token for the monitoring API. The API validates the token and independently checks whether the engineer is allowed to view the requested customer's information.
Situation | Intended outcome | What must be checked |
|---|---|---|
Engineer requests an assigned customer's report | Allow if all conditions pass | Token validity, API audience and customer permissions |
Engineer requests another customer's report | Deny unless explicitly permitted | Tenant and object-level access rules |
Token is expired | Reject or follow the supported renewal flow | Expiry and refresh behaviour |
Engineer leaves the business | Remove access according to policy | Identity account, grants, sessions, tokens and caches |
A successful login is only the start. The API must enforce the right access for each request, and the organisation must test what happens when a person's role or employment changes.
Common token problems
Expired token: the client needs a supported renewal or a fresh sign-in.
Wrong audience: the token was issued for a different API or application.
Untrusted issuer or signing key: the recipient does not recognise the authority or current key.
Insufficient permission: the token is valid but the requested action is not allowed.
Refresh failure: the refresh token has expired, been revoked or failed a rotation check.
Access persists after logout: the session and token lifecycles are not connected as expected.
Check the failing stage using provider and application documentation, safe correlation identifiers and timestamps. Never paste live tokens into public support tickets, test websites or screenshots. Check clock synchronisation, deployment configuration and key rotation where relevant.
How to review a token based design
Identify each token type, issuer, intended recipient and purpose.
Use the appropriate maintained protocol library and supported secure flow.
Check issuer, audience, expiry and other required validation rules.
Protect tokens in transit and storage, and remove them from logs and URLs.
Apply least privilege and enforce resource-level permissions at the API.
Test invalid, expired, wrong-audience and insufficient-permission cases.
Test refresh, revocation, account removal, logout, key rotation and outages.
Use authorised test accounts and non-sensitive data. Monitor unusual usage and have a response plan for suspected credential exposure. A token that passes validation is not a substitute for checking what the caller is allowed to do.
Key takeaway
Token based authentication uses a token as part of a trusted relationship between a client and a service. The token's type, intended recipient, validation rules and permissions matter more than its format. Protect tokens and test their complete lifecycle, including access removal and failure cases.
Frequently asked questions
What is token based authentication?
It is a way for a client to present a token as part of an authenticated relationship with a service, which validates the token and applies the relevant rules.
Is an access token proof that a user has logged in?
Not necessarily. An access token grants access to a resource under its protocol and may represent a client rather than a human user. Use the appropriate authentication protocol and validation.
Are all tokens JWTs?
No. Tokens can be JWTs or opaque values, among other formats. The recipient must use the validation method appropriate to the issuing system.
Is a signed JWT encrypted?
Not necessarily. A signature protects integrity when correctly verified, but readable claims are not hidden unless suitable encryption is also used.
What is a refresh token?
A refresh token is a credential that can be used with the authorisation server to obtain replacement tokens where supported.
Does signing out immediately invalidate every token?
Not necessarily. Sessions, grants, refresh tokens and access tokens have separate lifecycles. Actual behaviour depends on the application, provider and revocation design.
Can a stolen bearer token be used by someone else?
Often yes, until it expires or another effective control prevents use. Protect bearer tokens and follow the provider's incident and revocation procedures if one is exposed.

