Why claims need checking
A valid signature proves who issued a token and that it is unchanged. It does not prove the token is meant for you, or that it is still valid. A token for another API, from another realm, or from last week can carry a perfect signature.
That is why RFC 7519 and the OAuth best-practice documents ask resource servers to check claims after the signature: the times, the issuer and the audience at the least. This tool runs those checks the way a careful API would, and explains each result.
The checks, one by one
| Claim | Rule | Fails when |
|---|---|---|
exp | The current time must be before it | The token has expired |
nbf | The current time must be at or after it | The token is not valid yet |
iat | Should not be in the future | The issuer’s clock is ahead, or the token is forged |
iss | Must equal the issuer you trust, exactly | Another realm, host, scheme or path |
aud | Must contain your API’s identifier | The token was issued for someone else |
azp | If you check it, must be the expected client | Another client obtained the token |
typ (claim) | If you check it, must be the expected type | An ID token sent as an access token |
All time checks allow a small clock skew in both directions, set in seconds. The default here is 30.
Exact issuer matching
Issuers are compared as strings, character for character. https://auth.example.com/realms/acme and https://auth.example.com/realms/acme/ are different issuers. So are http and https, and a host name and its IP address. The tool points out when only a trailing slash differs.
Audience as a string or a list
RFC 7519 allows aud to be one string or an array. Your check should pass if any entry matches. Enter several expected values separated by commas and the tool passes if any one of them is in the token.
How to validate a token
- Paste the token. A sample issued a minute ago is filled in to show how the checks look.
- Enter the expected issuer, for Keycloak
https://<host>/realms/<realm>. - Enter the expected audience: your API’s client id, or the value your Audience mapper adds.
- Optionally enter the expected
azpandtypclaim. - Set the clock skew you allow, then read the checks from top to bottom.
The checks run against your computer’s clock, updated every second.
How Keycloak fills these claims
Issuer
Keycloak sets iss to the realm’s URL: https://<host>/realms/<realm>. The host part comes from how Keycloak sees the request or from its hostname setting, so a token obtained through an internal address can carry a different issuer than one obtained through the public address. The realm’s discovery document at /realms/<realm>/.well-known/openid-configuration shows the issuer for that address.
Audience
By default Keycloak puts into aud the clients whose client roles appear in the token. Users have roles of the account client by default, so aud often contains account. To add your API, create an Audience mapper in a client scope the calling client uses, and set it to your API’s client id.
Authorized party and type
Keycloak sets azp to the client id that requested the token. It also sets a typ claim: Bearer in access tokens and ID in ID tokens. Checking typ stops a client from sending an ID token where an access token is expected.
Times
Access tokens expire after the Access Token Lifespan, 5 minutes by default, set under Realm settings, Tokens and overridable per client. iat is the issue time; nbf is usually absent.
Use cases
An API returns 401 for valid-looking tokens
Paste a failing token and your API’s configured issuer and audience. The first failed check is usually the answer: a trailing slash in the issuer, a missing audience, or an internal host name in iss.
Writing the validation code
Use the tool as a reference while you configure a JWT library. Every library has settings for issuer, audience and clock skew; they should give the same results as here.
Checking a new client or mapper
After adding an Audience mapper or a new client scope, get a fresh token and confirm the claims changed the way you meant.
Common failures and fixes
| Result | Usual fix |
|---|---|
| Issuer does not match, only a trailing slash differs | Configure the issuer exactly as in the discovery document |
| Issuer has an internal host name | Request tokens through the public address, or set Keycloak’s hostname |
Audience does not match, token has account | Add an Audience mapper for your API |
| Expired, though just issued | Check the clocks on both machines; sync them with NTP |
Token type does not match, token has ID | The client sent its ID token; it should send the access token |
The same checks in code
Most JWT libraries do these checks for you once configured. In pseudo-code, the order looks like this.
verify signature with the issuer’s keys, algorithm pinned to RS256
now = current time in seconds
reject if now >= exp + skew
reject if nbf and now < nbf - skew
reject if iss != "https://auth.example.com/realms/acme"
reject if "orders-api" not in aud (string or list)
optionally reject if azp not in allowed clients
optionally reject if typ claim != "Bearer"The values here are samples. Use your realm’s exact issuer and your API’s audience.
Validating ID tokens in a client app
A client app that receives an ID token checks a slightly different set of claims, defined in OpenID Connect Core.
issmust be the provider’s issuer, andaudmust contain the client’s own client id.- If
audhas several values,azpshould be present and equal to the client id. expmust be in the future, andiatreasonably recent.- If the app sent a
noncein the authorization request, the ID token’snoncemust match it.
Set the expected audience to your client id and the expected typ to ID to run these checks on a Keycloak ID token here.
Checks this tool leaves to you
Some checks depend on your application and cannot be done from the token alone.
- Scopes: whether
scopecontains what the endpoint needs, such asorders:write. - Roles: whether the caller has the role the action needs; see the token roles viewer.
- Nonce: whether an ID token’s
noncematches the one your app sent. - Replay: whether a
jtiwas seen before, for one-time tokens.
Run the same token through this tool with the values from your API’s configuration. If the tool passes and the API still rejects the token, the problem lies in how the API reads its configuration, not in the token.
Limits of this tool
The tool does not check the signature. Claims in an unverified token prove nothing, because anyone can write them. Verify the signature first with the signature verifier.
It also cannot tell whether a token was revoked or its session ended; that needs a call to the authorization server, such as token introspection.
The sample token on this page is unsigned and made up. Its times follow your clock so the checks have something live to show.
Best practices for resource servers
- Check the signature, then
exp,nbf,issandaud, on every request. - Allow a small clock skew, 30 to 60 seconds, not minutes.
- Configure one exact issuer per trusted realm.
- Require your own audience; do not accept tokens meant for other APIs.
- Reject ID tokens at APIs by checking the token type.