You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Map user attributes from User Storage Provider to Access Token
#13883
I'm implemented a user storage provider to get users from external legacy database. Now I can search for users in the admin console and view their attributes. I created a mapper in one of the client scopes that I have in my realm that takes the attributes of the users and adds in the token, but the attributes of the users returned from the SPI are not obtained in the token, but when I create a user in the keycloak itself and set attributes for it, those attributes appear in the token.
It is hard to comment without seeing actual implementation on how you map external user to keycloak's UserModel, but
I guess you are using some sort of UserRepresentation to map user loaded from external storage, such representation should override a method @Override public Map<String, List<String>> getAttributes(), this is where you should do the mapping for your roles in order to be visible in the token.
e.g.
@Override
public Map<String, List<String>> getAttributes() {
MultivaluedHashMap<String, String> attributes = new MultivaluedHashMap<>();
attributes.add(UserModel.USERNAME, getUsername());
attributes.add(UserModel.EMAIL,getEmail());
attributes.add(UserModel.FIRST_NAME,getFirstName());
attributes.add(UserModel.LAST_NAME,getLastName());
return attributes;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
I'm implemented a user storage provider to get users from external legacy database. Now I can search for users in the admin console and view their attributes. I created a mapper in one of the client scopes that I have in my realm that takes the attributes of the users and adds in the token, but the attributes of the users returned from the SPI are not obtained in the token, but when I create a user in the keycloak itself and set attributes for it, those attributes appear in the token.
All reactions
Replies: 1 comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
It is hard to comment without seeing actual implementation on how you map external user to keycloak's
UserModel, butI guess you are using some sort of
UserRepresentationto map user loaded from external storage, such representation should override a method@Override public Map<String, List<String>> getAttributes(), this is where you should do the mapping for your roles in order to be visible in the token.All reactions