What token introspection is
Token introspection lets a protected resource ask the authorization server one question: is this token still good, and what does it mean? The answer comes back as JSON. The protocol is defined in RFC 7662, OAuth 2.0 Token Introspection.
It exists because some tokens cannot be checked locally. An opaque access token is just a random string; only the server that issued it knows what it stands for. A JWT access token can be validated with the issuer’s public key, but a signature check alone cannot tell you that the token was revoked or that the user’s session ended a minute ago. Introspection asks the source of truth.
The caller is usually an API, called a resource server in OAuth terms. A client app rarely needs introspection, because it should treat its own access token as opaque and simply use it.
How an introspection request works
The resource server sends a POST to the introspection endpoint with the token in a form-encoded body. It authenticates itself while doing so, because the answer reveals details about a token and its user. RFC 7662 leaves the exact authentication method to the server; client credentials are the common choice.
The request
POST /realms/acme/protocol/openid-connect/token/introspect HTTP/1.1
Host: auth.example.com
Content-Type: application/x-www-form-urlencoded
Authorization: Basic d2ViLWFwcDpzYW1wbGUtc2VjcmV0LW5vdC1yZWFs
token=SAMPLE_ACCESS_TOKEN&token_type_hint=access_tokenOnly token is required. token_type_hint is optional and may be access_token or refresh_token. It only helps the server look the token up faster; a server that cannot find the token with the hint must still search other types.
The response
{
"active": true,
"client_id": "web-app",
"username": "alice",
"scope": "openid profile email",
"sub": "1f8f4b3a-sample",
"exp": 1900000300,
"iat": 1900000000,
"token_type": "Bearer"
}The only required field is active. For an active token the server usually adds fields such as scope, client_id, username, sub, aud, iss, exp and iat. For a token that is expired, revoked, unknown, malformed or issued to someone else, the answer is just {"active": false}. RFC 7662 section 2.2 says the server should not explain why, so the caller learns nothing it could abuse.
What this tool does
The tool builds the introspection request for you and shows it two ways: as a curl command you can paste into a terminal, and as the raw HTTP request. Nothing is sent. Every value stays in your browser.
- It builds Keycloak’s endpoint from a server URL and realm name, or takes any custom introspection URL.
- It adds the token and an optional
token_type_hint. - It applies client authentication:
client_secret_basic(an Authorization header),client_secret_post(secret in the body), or a signed JWT assertion you paste in forprivate_key_jwtorclient_secret_jwt. - It shows a made-up sample of an active response, so you know what to expect.
It does not call the server, check a signature or decode the token. To read the claims inside a JWT, use the JWT decoder. To read a response you already have, use the token introspection viewer.
How to use the tool
- Choose Keycloak realm and enter your server URL and realm, or switch to Custom URL and paste the introspection endpoint from your discovery document.
- Paste the token you want to check. A placeholder is filled in so the page works on first load.
- Pick a
token_type_hintif you know the type, or leave it unset. - Choose how the calling client authenticates and enter its client id and secret, or paste a signed client assertion.
- Copy the curl command, or switch to the HTTP view to see the exact headers and body.
- Run the request from a machine you trust and check
activebefore reading anything else.
Introspection in Keycloak
In Keycloak each realm has its own introspection endpoint at https://<host>/realms/<realm>/protocol/openid-connect/token/introspect. The discovery document at /realms/<realm>/.well-known/openid-configuration lists it as introspection_endpoint. You can read that document with the OIDC discovery viewer.
Call it with the credentials of a confidential client, one with Client authentication turned on. A common setup is a dedicated client for each API, used only for introspection.
A token from another realm is answered with active: false, because each realm is its own issuer with its own keys and sessions.
When to use introspection
Introspection costs a network call per check, so use it where it pays off.
APIs that must notice revocation quickly
An API that moves money, changes permissions or deletes data may want to know at once when a user signs out or an admin ends a session. Local JWT validation keeps accepting a token until exp. Introspection reflects the server’s current state.
Gateways and reverse proxies
An API gateway can introspect incoming tokens once and pass trusted claims to the services behind it. Cache the result for a short time, well under the token lifetime, to keep the load reasonable.
Debugging a token
When an API rejects a token and you do not know why, introspection tells you whether the server still considers it active. If it says active: false, the problem is the token or the session, not your API code.
When not to use it
Single-page apps, mobile apps and command-line tools should not introspect. They cannot keep the credentials introspection requires, and they should not depend on the content of an access token at all. If such an app needs user details, it should read the ID token or call the UserInfo endpoint.
Introspection or local JWT validation
| Introspection | Local JWT validation | |
|---|---|---|
| Network call | One per check (or per cache miss) | None after the keys are fetched |
| Sees revocation and logout | Yes | No, only exp |
| Works with opaque tokens | Yes | No |
| Needs client credentials | Yes | No, only the public keys |
Many teams combine the two: validate the JWT locally on every request, and introspect only for sensitive operations. To validate locally, fetch the realm’s keys from its JWKS endpoint and check the signature, iss, aud and exp. The JWT verifier shows how those checks fit together.
Common errors and how to fix them
Always active: false
- The token expired. Check
expwith the JWT decoder. - The token comes from another realm or another server. Compare its
isswith the endpoint you call. - You sent
Bearerin front of the token. Send the token alone. - The user’s session ended, or the token was revoked.
401 with invalid_client
The client credentials are wrong, or the client id is unknown in this realm. Call with a confidential client and check its secret. If the secret has special characters, see the client authentication header tool for how it must be encoded.
unsupported_grant_type or a 404
You probably posted to the token endpoint instead of the introspection endpoint, or left out /introspect at the end of the path.
Security notes
- Call introspection only over https, and only from back-end code.
- Give the introspecting client the least it needs, and use it for nothing else.
- Do not log full tokens or full introspection responses. They identify users and can be replayed until they expire.
- Check
activefirst. A field such asscopemeans nothing when the token is not active. - Check the audience. An active token issued for another API is still not meant for yours. RFC 9700, the OAuth security best current practice, recommends restricting access tokens to the resource they are meant for.
Best practices
- Cache positive answers briefly, keyed by a hash of the token, and never past the token’s
exp. - Keep negative answers out of a long cache, and never record a network failure as
active: false. - Treat a failed call as a failure, not as an inactive token. Return 503 rather than 401 if the server cannot be reached.
- Send
token_type_hintwhen you know the type; it saves the server a lookup. - Keep the introspection client separate from clients that users sign in through.
If you would rather not run the server side of this yourself, RealmDeploy runs upstream Keycloak for you on a dedicated cluster. The plans are on pricing.