# Fetch custom userinfo (declarative-user-profile)

**URL:** <https://forum.keycloak.org/t/fetch-custom-userinfo-declarative-user-profile/24303>\
**Category:** Getting advice\
**Created:** [January 30, 2024, 4:41pm UTC](https://forum.keycloak.org/t/fetch-custom-userinfo-declarative-user-profile/24303 "2024-01-30T16:41:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BenoitC](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/benoitc/32/9649_2.png) [@BenoitC](https://forum.keycloak.org/u/BenoitC)\
**Post date:** [January 30, 2024, 4:41pm UTC](https://forum.keycloak.org/t/fetch-custom-userinfo-declarative-user-profile/24303/1 "2024-01-30T16:41:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [January 30, 2024, 4:47pm UTC](https://forum.keycloak.org/t/fetch-custom-userinfo-declarative-user-profile/24303/2 "2024-01-30T16:47:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BenoitC](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/benoitc/32/9649_2.png) [@BenoitC](https://forum.keycloak.org/u/BenoitC)\
**Post date:** [January 31, 2024, 9:25am UTC](https://forum.keycloak.org/t/fetch-custom-userinfo-declarative-user-profile/24303/3 "2024-01-31T09:25:44Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [January 31, 2024, 11:01am UTC](https://forum.keycloak.org/t/fetch-custom-userinfo-declarative-user-profile/24303/4 "2024-01-31T11:01:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BenoitC](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/benoitc/32/9649_2.png) [@BenoitC](https://forum.keycloak.org/u/BenoitC)\
**Post date:** [February 1, 2024, 12:12pm UTC](https://forum.keycloak.org/t/fetch-custom-userinfo-declarative-user-profile/24303/5 "2024-02-01T12:12:54Z")

</div>

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’.
