Fetch custom userinfo (declarative-user-profile)

I have activated the declarative-user-profile and added a property called ‘country,’ which I have enabled for the ‘email’ scope. Can I retrieve the value of ‘country’ via /realms/MYREALM/protocol/openid-connect/userinfo?

For your information, I have tested by generating a token with the ‘email’ scope, but I cannot retrieve ‘country’ by calling /realms/MYREALM/protocol/openid-connect/userinfo.

Thank you for your help.

You will have to create a mapper, that your desired user attribute will get mapped to the token.
As you are using the email scope, you should add the mapper to the email client scope configuration.

Thanks @dasniko,

What type of mapper should I create? I tried unsuccessfully with ‘User Property’ and ‘User Attribute.’
I set: “User Attribute”: “country”, “Token Claim Name”: “country”, and checked “Add to userinfo” but when I call /realms/MYREALM/protocol/openid-connect/userinfo there is no property country in the response. But country is a property of “User Profile” (flag declarative-user-profile).

A user attribute mapper is the proper one.
Don’t know what exactly is missing/wrong. The steps you described sound correct.

  • You added the mapper to the email Client Scope?
  • The access_token used to call the userinfo endpoint was created with email scope?

If this doesn’t work, I’d have to look into the details to get an idea.

Thanks @dasniko,

The country was not set for the user, which is why the ‘country’ property was not included in the response for the ‘userinfo’.

1 Like