What token introspection is
Token introspection (RFC 7662) lets a resource server ask the authorization server: is this token valid right now, and what does it say? The server answers with a JSON object whose active member is true or false, plus details about the token when it is active.
Introspection works for any kind of token, including opaque tokens that are just random strings. For JWTs it adds something local validation cannot give: knowledge of revocation and ended sessions. A JWT whose signature and expiry look fine can still be inactive because the user signed out.
How an introspection call works
The resource server sends a POST to the introspection endpoint, form-encoded, with the token in the token parameter. It authenticates as a client, for example with HTTP Basic using its client id and secret.
POST /realms/acme/protocol/openid-connect/token/introspect
Host: auth.example.com
Authorization: Basic b3JkZXJzLWFwaTpzYW1wbGUtc2VjcmV0
Content-Type: application/x-www-form-urlencoded
token=eyJhbGciOi…The introspection request builder writes this request for you as curl or HTTP.
The response members
| Member | Meaning |
|---|---|
active | Required. true if the token is valid now, otherwise false |
scope | Space-separated scopes granted to the token |
client_id | The client the token was issued to |
username | A human-readable name of the user |
token_type | The type of token, such as Bearer |
exp, iat, nbf | Times, in Unix seconds |
sub, aud, iss, jti | Subject, audience, issuer and token id |
All members except active are optional, and servers may add their own. When active is false, RFC 7662 says the server should not include anything else, and clients must not rely on any other member.
What this viewer does
- Shows clearly whether the token is active.
- Lists the granted scopes as badges.
- Shows the standard members with a note on each, and times as dates with how long ago or from now.
- Flags a missing or non-boolean
active, extra members on an inactive response, and an active token whoseexphas passed. - Lists all other members separately, such as the token’s own claims.
- Reads JWT responses (RFC 9701) from their
token_introspectionclaim.
It reads a response you paste. It does not call any server, so you need to make the request yourself.
How to read a response
- Call the introspection endpoint with the token and your client’s credentials.
- Paste the JSON response.
- Read the status first. If it says “Not active”, the token must be rejected, whatever else you see.
- For an active token, check scope, client, user and times against what your API expects.
Introspection in Keycloak
A Keycloak realm’s endpoint is https://<host>/realms/<realm>/protocol/openid-connect/token/introspect, listed in the discovery document as introspection_endpoint. The caller must authenticate as a client of the realm, typically a confidential client representing your API.
For an active token, Keycloak returns the token’s claims, such as realm_access, resource_access and preferred_username, together with active and introspection members such as client_id and username. For an expired, revoked or unknown token it returns {"active": false}.
Lightweight access tokens
Recent Keycloak versions can issue lightweight access tokens that leave most claims out, to keep tokens small. Resource servers then call introspection to get the full set of claims. The client setting for this is in its advanced settings.
When tokens become inactive
A Keycloak access token becomes inactive when it expires, when its user session ends (sign-out, session timeout, or an admin ending the session), or when it is revoked. Introspection reflects all of these; local JWT validation sees only expiry.
Use cases
Catching revoked tokens
For sensitive operations, such as payments or admin actions, an API can introspect even JWTs, so a sign-out takes effect at once instead of when the token expires.
Opaque tokens
When tokens are not JWTs, introspection is the only way for an API to learn anything about them.
Debugging “active: false”
Paste the response alongside the JWT decoder output for the same token. If the JWT has not expired but introspection says inactive, the session ended or the token was revoked.
Common problems
| Symptom | Likely cause |
|---|---|
| 401 from the introspection endpoint | Wrong client credentials, or a public client trying to introspect |
active: false for a fresh token | Token from another realm, or its session already ended |
active: false after a sign-out | Expected: the session ended, so its tokens are inactive |
active is the string "true" | A broken server or proxy; it must be a JSON boolean |
Introspection compared with local validation
Resource servers have two ways to check an access token. Each has a place.
| Local JWT validation | Introspection | |
|---|---|---|
| Network call per request | No | Yes, unless cached |
| Sees revocation and ended sessions | No, only expiry | Yes |
| Works with opaque tokens | No | Yes |
| Needs client credentials | No | Yes |
| Load on the authorization server | Only fetching keys | One call per check |
A common design validates locally for ordinary reads, and introspects before actions that must respect a sign-out at once. Short access token lifetimes narrow the gap for everything else.
Setting up an introspecting client in Keycloak
- Create a client for your API, for example
orders-api, with Client authentication turned on so it is confidential. - It does not need any login flow; you can turn off the standard flow for it.
- Copy its secret from the Credentials tab and store it in the API’s secret store.
- Call the introspection endpoint with HTTP Basic using that client id and secret.
The API then sees the same claims a JWT would carry, plus active. Keep the secret on the server; it must never reach a browser.
Caching responses safely
Introspecting every request can put real load on the authorization server. Caching helps, at the cost of noticing revocation later.
- Key the cache by a hash of the token, not the token itself.
- Cache active responses for a short time, such as a few seconds to a minute.
- Never keep a response past the token’s
exp. - Do not cache inactive responses for long; a retry with the same token should fail quickly anyway.
Log the outcome of introspection calls without logging the token itself. A count of inactive results per client is a useful signal: a sudden rise often means a sign-out wave, a misconfigured client, or someone replaying old tokens.
If your API runs several instances, a shared cache avoids each instance introspecting the same token separately.
Security notes
Only authenticated clients should be able to introspect, otherwise the endpoint becomes a way to test stolen tokens. Use a confidential client for your API and keep its secret on the server.
Caching responses saves round trips but delays revocation. If you cache, keep the cache short and never past the token’s exp.
The sample response on this page is made up. It shows the shape of an active response for the realm acme.
Best practices
- Check
activefirst, and treat anything other than the booleantrueas inactive. - Use introspection where revocation must take effect quickly; validate JWTs locally elsewhere.
- Authenticate the introspecting client and limit which clients may do it.
- Combine introspection with your own scope and audience checks.