Why compare two tokens
When something works in one place and not in another, the difference is often in the token. A user who can open a page in staging but not in production, a client that suddenly lost a role, an API that accepts tokens from one app and rejects the other: comparing two tokens side by side shows what changed in seconds.
Reading two long payloads by eye is slow and error-prone, especially with nested role claims. This tool decodes both tokens and lists every field that was added, removed or changed.
How the comparison works
Both tokens are decoded: header and payload, from Base64url to JSON. Then the two JSON objects are walked key by key. Nested objects are compared member by member, so a change deep inside resource_access is reported with its full path. Lists are compared as a whole, so a role list with one extra entry shows as changed, with both versions side by side.
| Change | Meaning |
|---|---|
| added | The field exists only in token B |
| removed | The field exists only in token A |
| changed | The field exists in both with different values |
| same | Identical in both; hidden unless you ask to see it |
Time claims are shown both as numbers and as dates, so a changed exp is easy to read. The tool also notes when the two signatures are identical, which only happens when the tokens are identical.
realm_access.roles changed
A: ["default-roles-acme", …, "order-manager"]
B: ["default-roles-acme", …, "order-manager", "billing-viewer"]How to compare tokens
- Paste the first token into Token A.
- Paste the second token into Token B.
- Read the count of differences, then the header table and the payload table.
- Tick “Show unchanged claims too” to see the full picture.
Put the older or working token in A and the newer or failing one in B. Then “added” and “removed” read naturally.
What usually differs
Some differences are expected every time. Others are the clue you are looking for.
Always different
Two tokens issued at different times differ in iat, exp and jti, and usually in the signature. Tokens from different sessions also differ in sid. These differences are normal.
Worth a closer look
iss: the tokens come from different realms or hosts.aud: an Audience mapper or client scope changed, or a different client asked.azp: a different client requested the token.realm_accessandresource_access: roles were added or removed, or scope rules changed.scope: the client asked for different scopes, or a client scope moved between default and optional.- Header
kidoralg: the realm rotated keys or changed its signature algorithm.
Use cases with Keycloak
Before and after a configuration change
Get a token, change a mapper, a client scope or a role, get another token, and compare. You see exactly what the change did to the token, and nothing else. The admin console can also generate example tokens: open the client, then Client scopes, then Evaluate, choose a user and generate an access token.
Staging against production
Realm exports drift. Compare a token for the same user and client in both environments to find a missing mapper or a different default scope. For the realm configuration itself, the realm export diff compares whole exports.
Two clients, one user
A user’s token from a web app and from a mobile app can differ because each client has its own scopes, mappers and role scope. Comparing them shows why one app sees a role and the other does not.
Before and after a refresh
Compare the first access token with one obtained by refreshing. Keycloak issues fresh times and id, while auth_time and sid stay the same. If roles changed in between, the refreshed token shows them.
Reading role changes
A role can disappear from a token for reasons that have nothing to do with the user. In Keycloak, a client sees only the roles its scope allows: when Full scope allowed is off on the client’s dedicated scope, only roles in its scope mappings reach the token. A role also needs the roles client scope to be assigned so the mappers that write realm_access and resource_access run.
When the diff shows a role missing, check the user’s role mappings first, then the client’s scope. The token roles viewer lists the roles in a single token clearly.
A worked example: a role that went missing
Suppose users of the web app can no longer create orders, while staff using the admin app still can. Here is how a comparison narrows it down.
- Get an access token for the same user from each app, or generate both in the admin console with Client scopes, Evaluate on each client.
- Paste the web app’s token into A and the admin app’s into B.
- The diff shows
azpchanged, as expected, andresource_access.orders-apipresent only in B. - That means the web app’s client is not allowed to see the
orders-apiroles: its dedicated scope has Full scope allowed off and no scope mapping for them. - Add the scope mapping for the needed role, get a new token, and compare again to confirm.
The whole investigation takes minutes because the token states exactly what the API sees.
Comparing headers
Header differences are rarer, and more telling when they happen.
| Header field changed | Usual reason |
|---|---|
kid | The realm rotated keys, or the tokens come from different realms |
alg | The realm or client signature algorithm was changed |
typ | Different issuers, or a token type setting was changed |
If kid differs, check that both keys are in the realm’s key set with the key id matcher. An API that cached the old set will reject tokens with the new kid until it refreshes.
Getting comparable tokens
The best comparisons hold everything constant except the thing you study. Use the same test user, request the same scopes, and get both tokens close together in time. If you compare environments, use the same client id in both. The admin console’s Client scopes, Evaluate tab helps here, because it produces tokens without signing in through an app.
Limits
- Signatures are not checked. A forged token compares just as easily as a real one; use the signature verifier when it matters.
- Lists are compared whole. When two long role lists differ, compare the two lines shown to spot the entry.
- Encrypted tokens (JWE) cannot be compared, because their payload is ciphertext.
Security notes
Both tokens are decoded in your browser and nothing is sent to us. Live tokens still grant access until they expire, so compare tokens from a test realm, or wait until they have expired.
The two sample tokens are made up: token B is token A after a refresh, with a role added and a scope removed. B has a placeholder signature.
Tips for useful comparisons
- Change one thing at a time between the two tokens.
- Use the same user and client unless the difference you study is the user or client.
- Ignore
iat,exp,jtiand the signature unless timing is the question. - Keep a known-good token from a test realm to compare against later.