# How to get user email from token code?

**URL:** <https://forum.keycloak.org/t/how-to-get-user-email-from-token-code/8337>\
**Category:** Getting advice\
**Created:** [April 6, 2021, 9:16pm UTC](https://forum.keycloak.org/t/how-to-get-user-email-from-token-code/8337 "2021-04-06T21:16:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gch](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/gch/32/1801_2.png) [@gch](https://forum.keycloak.org/u/gch)\
**Post date:** [April 6, 2021, 9:16pm UTC](https://forum.keycloak.org/t/how-to-get-user-email-from-token-code/8337/1 "2021-04-06T21:16:54Z")

</div>

Hello everybody,

I’m starting in Keycloak and sorry in advance for my silly question.

I have installed a service provider with keycloak, added a identity provider and succeeded in connecting to it.  
Now I try to extract the email from the user with this following request :  
‘url’ =\> ‘[SERVER]/auth/realms/sp\_realm/protocol/openid-connect/userinfo’,  
‘token’ =\> $token\_code[‘access\_token’],  
‘content\_type’ =\> ‘application/json’,  
‘scope’ =\> ‘openid profile email’,  
‘method’ =\> ‘POST’,  
but with that, I just obtained the following fields :  
name, sub and email\_verified  
and I need to have the field “email”.

What do I have to do for it ?

Thanks in advance for your help

---

<div class="post-metadata">

**Author:** ![Cyben](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/cyben/32/2547_2.png) [@Cyben](https://forum.keycloak.org/u/Cyben)\
**Post date:** [April 7, 2021, 4:06pm UTC](https://forum.keycloak.org/t/how-to-get-user-email-from-token-code/8337/2 "2021-04-07T16:06:50Z")

</div>

I am not quite sure and I don’t have an access to keycloak right now but if I remember correctly email is a mapper in one of the default client scopes, and if you go to the mapper there is an toggle that you could change between true or false if you would like to display this mapper in an ‘access token’, ‘id token’, and ‘user info’.

Hope I remember correctly and didn’t mislead you.

---

<div class="post-metadata">

**Author:** ![gch](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/gch/32/1801_2.png) [@gch](https://forum.keycloak.org/u/gch)\
**Post date:** [April 7, 2021, 4:18pm UTC](https://forum.keycloak.org/t/how-to-get-user-email-from-token-code/8337/3 "2021-04-07T16:18:30Z")

</div>

> [@Cyben](#):
>
> toggle

Thanks a lot Cyben ! I’ve found in Client Scopes \> email \> Mappers \> email a ON/OFF button “Add to userinfo”.

 ![Capture d’écran du 2021-04-07 18-16-23](https://global.discourse-cdn.com/free1/uploads/keycloak/original/2X/8/8a56a78fc105ba7cccbc31eab023160d70582aed.png)

---

<div class="post-metadata">

**Author:** ![Cyben](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/cyben/32/2547_2.png) [@Cyben](https://forum.keycloak.org/u/Cyben)\
**Post date:** [April 7, 2021, 6:02pm UTC](https://forum.keycloak.org/t/how-to-get-user-email-from-token-code/8337/4 "2021-04-07T18:02:18Z")

</div>

Awesome! Your welcome
