简体   繁体   中英

Get user group info in keyclock in angular application?

I know keycloak set user info in local storage from where you can get a user name and email id etc. But I wanted to know how can I get details of the group(s) user belong to.

This question is a bit abstract, but to get the group details, this has to be already available in the JWT token.

Once you create a group and user in Keyclock, you have to map the user to the respective group. A user can be part of one or more groups.

Then you have to create a mapper to add the group details in the JWT token as follows.

Go to:

Clients > your client name > Mappers

Create a new mapper with following details:

Name: Some unique name Mapper Type: Group membership Token Claim Name: groups (this can be any name, and group details will be available in JWT under this name)

Set all the following selectors in "ON" mode.

Save the changes.

Request for a new token and you will see group details added to JWT token on inspection.

This can be accessed using the respective library that is being used at the client side.

For example if you are using oidc-client in angular, then you can access it at user.profile.groups

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM