How to get Keycloak's roles? #8584
-
I wanted to come back on this issue : #4811 I check both The only way i found to get the roles are to parsed the token myself : import jwt from 'jsonwebtoken'
//...
callbacks: {
//...
jwt: async (params) => {
let roles = undefined as
| { [key: string]: { roles: Array<any> } }
| undefined
if (account?.access_token) {
let decodedToken = jwt.decode(account?.access_token)
if (decodedToken && typeof decodedToken !== 'string') {
roles = decodedToken?.resource_access
}
}
//...
}
} I'm not really comfortable with this approach and i'm wondering why it's missing from Is this happening because other providers doesn't define these fields ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
@LoiKos, what version of Keycloak are you using? There is a way to include the roles as part of the access token. |
Beta Was this translation helpful? Give feedback.
@LoiKos, what version of Keycloak are you using? There is a way to include the roles as part of the access token.