Skip to content

Keycloak token roles viewer

List the realm roles and client roles in a Keycloak access token, client by client, and check whether it carries a given role.

Runs in your browser. Nothing you paste is sent to us.

Token

A sample access token for the made-up realm acme is filled in. Paste yours; it stays in your browser.

Found
orders:write: client role of orders-api.
Realm
acme
Client (azp)
web-app
User
alice

Roles

Realm roles (realm_access.roles)

RoleNote
default-roles-acmeThe realm’s default role, given to every new user
offline_accessAllows offline tokens (the offline_access scope)
uma_authorizationA default role used by User-Managed Access (UMA)
order-manager

Client roles (resource_access)

ClientRoles
orders-api
orders:readorders:write
account
manage-accountmanage-account-linksview-profile
scope
openid profile emailScopes are not roles, but they limit what the token is for
All roles, one per line (realm: or client:)
realm:default-roles-acme
realm:offline_access
realm:uma_authorization
realm:order-manager
orders-api:orders:read
orders-api:orders:write
account:manage-account
account:manage-account-links
account:view-profile

How to use it

  1. Paste a Keycloak access token.
  2. Read the realm roles from realm_access and the client roles from resource_access.
  3. Type a role name to see whether the token has it, and where.
  4. Copy the full list of roles, one per line.

What to know

Keycloak puts realm roles in realm_access.roles and client roles in resource_access.<client id>.roles. The mappers that add them belong to the roles client scope.

A role appears only if the user has it and the client is allowed to see it. When Full scope allowed is off for a client, only roles in its scope mappings are included.

Every realm gives new users the default role default-roles-<realm>, which by default includes offline_access and uma_authorization.

Roles in a Keycloak token

Keycloak has two kinds of role. Realm roles belong to the whole realm, such as admin or order-manager. Client roles belong to one client, such as orders:read on an orders-api client. Users get roles directly, through groups, or through composite roles that contain other roles.

When Keycloak issues an access token, it writes the roles the client is allowed to see into two claims. Your API reads those claims to decide what the caller may do. If a role is not in the token, your API cannot see it, whatever the admin console shows for the user.

Where the roles are in the token

Role claims in a sample access token for the realm acme
"realm_access": {
  "roles": ["default-roles-acme", "offline_access", "uma_authorization", "order-manager"]
},
"resource_access": {
  "orders-api": { "roles": ["orders:read", "orders:write"] },
  "account": { "roles": ["manage-account", "view-profile"] }
}
ClaimHolds
realm_access.rolesRealm roles, as a flat list
resource_access.<client-id>.rolesClient roles, grouped by the client that owns them
scopeThe scopes granted to the token; not roles, but often confused with them
groupsGroup paths, only if a group membership mapper adds them

Composite roles are expanded: if a user has a composite role, the token lists the composite and every role it contains.

What this viewer does

  • Lists realm roles with a short note for the roles every realm has.
  • Lists client roles in a table, client by client.
  • Answers “does this token have role X?” and says whether it is a realm role, a client role or a group.
  • Shows the realm (from iss), the client (azp) and the user.
  • Gives every role as one line, realm:role or client:role, ready to copy into a test or a ticket.

It also shows a groups claim and a custom roles claim if a mapper added them, and the token’s scopes.

Step by step

  1. Paste a Keycloak access token.
  2. Read the realm roles and the client roles tables.
  3. Type a role name in the search box to see whether the token carries it, and where.
  4. Copy the full list if you need it elsewhere.

Default roles every realm has

Each realm has a default role named default-roles-<realm>, which Keycloak gives to every new user. It is a composite role. By default it contains the realm roles offline_access and uma_authorization, and the account client’s roles view-profile and manage-account.

  • offline_access allows the user’s apps to request offline tokens with the offline_access scope.
  • uma_authorization is used by User-Managed Access.
  • view-profile and manage-account let the user use the account console.

Because the account client roles are in the token, Keycloak also adds account to the token’s audience. You can change what the default role contains under Realm settings, User registration.

How Keycloak decides which roles go in

The roles client scope

The realm_access and resource_access claims are written by mappers in the built-in roles client scope. A client that does not have this scope assigned gets tokens without them. Check under Clients, then your client, then Client scopes.

Full scope allowed

Each client has a dedicated scope with a Full scope allowed switch, on its Scope tab. When it is on, every role the user has can appear in the token. When it is off, only roles listed in the client’s scope mappings appear. Turning it off keeps tokens small and limits what a leaked token grants.

Access token, ID token, userinfo

The role mappers add roles to the access token. Adding them to the ID token or the userinfo response is a separate switch on each mapper. That is why an ID token often has no roles.

Try it without an app

In the admin console, open the client, then Client scopes, then Evaluate. Choose a user and generate an example access token. Paste it here to see exactly which roles that client would receive for that user.

Use cases

A user gets 403 from an API

Paste the token the API rejected and search for the role the API requires. If it is missing, the problem is in Keycloak’s configuration, not in the API.

Writing authorization rules

See the exact shape your code must read: client id keys under resource_access, role names as they appear, and whether you need realm or client roles.

Reviewing least privilege

A token that lists roles for many clients the app never calls is a sign that Full scope allowed is on. Each extra role is something a leaked token could be used for.

Why a role is missing

CheckWhere in the admin console
The user has the role, directly or through a groupUsers, the user, Role mapping
The client has the roles client scopeClients, the client, Client scopes
The role is allowed by the client’s scopeClients, the client, Client scopes, dedicated scope, Scope
The mapper adds roles to this kind of tokenClient scopes, roles, Mappers
The token is newGet a fresh token; old tokens keep old roles

Reading roles in your API

Once the token is verified, reading roles is a matter of walking two claims. Accept that either may be missing.

Reading roles from a verified token, sample client orders-api
const realmRoles = token.realm_access?.roles ?? [];
const apiRoles = token.resource_access?.['orders-api']?.roles ?? [];
const canWrite = apiRoles.includes('orders:write');

Many frameworks have Keycloak or OpenID Connect integrations that map these claims to their own role model. Check which claim they read: some default to realm roles only.

Composite roles, worked through

Suppose a realm role order-manager is a composite that contains the client roles orders:read and orders:write on orders-api. A user who has only order-manager gets a token with order-manager in realm_access.roles and both client roles under resource_access.orders-api, provided the client may see them.

This is why the roles in a token can be more than the roles you assigned directly. The admin console shows the expanded set on the user’s Role mapping tab when you turn off the filter that hides inherited roles.

Roles compared with scopes

Roles say what the user may do. Scopes say what the client asked to be allowed to do on the user’s behalf. An API can check both: the token’s scope must include the operation, and the user must have the role for it. In Keycloak, client scopes can also limit roles through their own Scope tab, which ties the two together.

Security notes

Roles in a token are only trustworthy after the signature is verified. Anyone can write admin into a payload; only the realm’s key can sign it. Verify with the signature verifier and check iss and aud before you rely on any role.

Role changes do not reach tokens already issued. A user whose role you removed keeps it until their access token expires, which is one reason to keep access tokens short-lived.

Best practices

  • Prefer client roles for permissions specific to one API, and realm roles for broad ones.
  • Turn off Full scope allowed and map only the roles each client needs.
  • Check roles in the API from verified tokens only.
  • Keep large group and role lists out of access tokens; they make tokens big.
Questions

Frequently asked questions

Why are my roles missing from the token?

Check that the user has the role, that the client has the `roles` client scope, and that the role is in the client’s scope when Full scope allowed is off. Then get a fresh token, because existing tokens keep their old roles.

Why are there roles in the access token but not in the ID token?

The role mappers in the `roles` client scope add roles to the access token. Adding them to the ID token is a separate setting on each mapper.

Are groups the same as roles?

No. Groups appear only if a group membership mapper adds a `groups` claim. Roles a user gets through a group are listed as roles.

What is `default-roles-<realm>`?

The realm’s default role, given to every new user. It is a composite that by default includes `offline_access`, `uma_authorization` and the account client’s `view-profile` and `manage-account`.

What is the difference between realm roles and client roles?

Realm roles apply across the realm and appear in `realm_access.roles`. Client roles belong to one client and appear under that client’s id in `resource_access`.

How do I see which roles a client would get without logging in?

Open the client in the admin console, go to Client scopes, then Evaluate. Choose a user and generate an example access token.

Why does my token list roles for clients my app never calls?

Full scope allowed is probably on for your client, so every role the user has is included. Turn it off and map only the roles the client needs.

Can I flatten the roles into one claim?

Yes, with a custom mapper, but most libraries already read `realm_access` and `resource_access`. This viewer shows a flat `roles` claim if a mapper adds one.

Do role changes show up in existing tokens?

No. A token keeps the roles it was issued with until it expires. The user gets the new roles in the next token, after a refresh or a new sign-in.

Why is `uma_authorization` in my token?

It is part of the realm’s default role, so every new user has it. It is used by User-Managed Access. Your API can ignore it unless it uses UMA.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.