Keycloak is the powerhouse for open-source Identity and Access Management (IAM), widely used to secure microservices, Spring Boot applications, and enterprise portals. However, Keycloak's token structure is notoriously complex, featuring deeply nested JSON objects for role mappings that can be difficult to read in raw format. Our Keycloak JWT Decoder is engineered specifically to help developers unpack these nested structures, verify client-specific roles, and debug authorization logic securely.
Because Keycloak tokens govern access to your entire infrastructure, pasting them into generic online debuggers is a severe security risk. Our tool processes everything locally in your browser, ensuring your production session data never leaves your device.
Decoding Keycloak's Nested Role Structures
Unlike Auth0 or Okta, which often flatten roles into a simple array, Keycloak uses a highly structured, nested approach to differentiate between global realm roles and application-specific client roles. The decoder formats these complex objects cleanly.
1. Realm Roles (realm_access)
Realm roles are global to the entire Keycloak realm. They apply to the user regardless of which application they are logging into. In the decoded payload, you will find them nested under the realm_access object:
{
"realm_access": {
"roles": ["offline_access", "uma_authorization", "admin"]
}
}2. Client Roles (resource_access)
Client roles are specific to a particular application (client) registered in Keycloak. They are nested under the resource_access object, keyed by the Client ID:
{
"resource_access": {
"my-frontend-app": {
"roles": ["editor", "viewer"]
},
"my-backend-api": {
"roles": ["api:write"]
}
}
}The decoder highlights these nested structures, making it instantly clear which roles belong to which application.
Inspecting Keycloak Scopes and Protocol Mappers
Keycloak uses Protocol Mappers to inject data into the token. If you have configured a mapper to include the user's email, groups, or custom attributes, the decoder will show you exactly what was injected. The scope claim will list the OAuth2 scopes requested by the client, while custom mappers will appear as root-level claims or nested objects depending on your configuration.
| Keycloak Claim | Purpose | What to Check in Decoder |
|---|---|---|
preferred_username | The user's login name | Ensure it matches the expected identity format. |
typ (Header) | Token type | Should be `Bearer` for Access Tokens, `ID` for ID Tokens. |
session_state | Keycloak session UUID | Useful for correlating logs and forcing remote logouts. |
allowed-origins | CORS configuration | Verify your frontend URL is listed to prevent CORS errors. |
Debugging Spring Boot and Microservices Authorization
If you are using Spring Security with Keycloak, your backend relies heavily on the resource_access and realm_access claims to grant method-level security (e.g., @PreAuthorize("hasRole('api:write')")). If a 403 Forbidden error occurs, pasting the token into this decoder is the fastest way to verify that Keycloak actually issued the required role to the user for that specific client.
Security: Protecting Open-Source Infrastructure
Keycloak is often used to secure highly sensitive internal infrastructure and government portals. A leaked Keycloak Access Token could grant an attacker administrative access to your entire realm. Our 100% client-side architecture guarantees that your IAM credentials are parsed in your browser's sandbox and never transmitted to an external server.
Troubleshooting Common Keycloak Errors
- Missing client roles: Ensure the 'Client Roles' mapper is enabled in your Client Scope settings. By default, Keycloak may not inject client roles into the Access Token unless explicitly mapped.
- "Invalid audience" error: Check the
azp(Authorized Party) andaudclaims. Theazpmust match the Client ID of the application that requested the token.
Final Thoughts
Keycloak's flexibility is its greatest strength, but also its greatest debugging challenge. The Keycloak JWT Decoder cuts through the nested JSON complexity, giving developers instant, secure visibility into realm roles, client roles, and protocol mappers, accelerating your microservices security workflow.