How to get user email from token code?

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

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.

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

1 Like

Awesome! Your welcome