Search code examples
keycloak

Keycloak - What is the best way to get User's role


Hi I'm using Keycloak and I would like to know what is the best way to get User Role. I'm using a SPA written in ReactJS and it needs to know the user's role. Is there a Keycloak API to get this? or should I get it from the JWT token. Either way, what is the option that I should go with. Thank you.


Solution

  • If you assigned role to a user, then this role is a claim inside JWT access token provided by Keycloak.

    A user would have to be authenticated before seeing some application content.

    After successful authentication, access token would be given to client (can be application gateway or ui application) and then role can be extracted from it and used.