I am currently trying to use Keycloak for authentication and authorization with a nuxt application. I am able to direct all authentication to Keycloak and get a OIDC JWT Token in response. The nuxt application is able to parse the response and grant access.
But it seems that not all of the information from the OIDC JWT token is available to my nuxt application. I would like to know which roles the user has, alongside with other attributes from the token.
Looking at the this.$auth.user I only get this information:
{
"sub": "af52eefc-377e-4fd4-8da7-e1c15118acb8",
"email_verified": true,
"name": "Kenneth Larsen",
"preferred_username": "xyz",
"given_name": "Kenneth",
"family_name": "Larsen",
"email": "xyz@mail.com"
}
I am able to get the full token from this.$auth.strategy.token.get() and if I decode it at jwt.io I get something like this:
{
"exp": 1615519947,
"iat": 1615519647,
"auth_time": 1615519285,
"jti": "054ef275-fe50-40b8-b283-087f544b3afc",
"iss": "https://example.com/auth/realms/testrealm",
"aud": "account",
"sub": "af52eefc-377e-4fd4-8da7-e1c15118acb8",
"typ": "Bearer",
"azp": "example.com",
"session_state": "98f74bbd-a626-4757-96de-4d860bdd45d1",
"acr": "1",
"allowed-origins": [
"https://example.com",
],
"realm_access": {
"roles": [
"offline_access",
"myrole01",
"myrole02",
"uma_authorization"
]
},
"resource_access": {
"account": {
"roles": [
"manage-account",
"manage-account-links",
"view-profile"
]
}
},
"scope": "openid email profile",
"email_verified": true,
"name": "Kenneth Larsen",
"preferred_username": "xyz",
"given_name": "Kenneth",
"family_name": "Larsen",
"email": "xyz@email.com"
}
I am aware that I could parse the token, but I expect that this is already done. Just can't find it anywhere.
Thanks