Extract user_metadata & app_metadata

Hello,
I am new with Auth0. I would like to receive user_metada & app_metadata within the ID_TOKEN or other part when I request a login. The request login is with php :
https://dev-6y43krdr.eu.auth0.com/authorize?
response_type=id_token token&
response_mode=form_post&
client_id=’.$client_id.‘&
client_secret=’.$client_secret.‘&
redirect_uri=’.$redir_uri_inp.‘&
scope=profile,email&
state=’.$state.‘&
nonce=CssGheServices’

Where is my mistake ? Tjanks a lot for help.
Gilbert

Hi @gheintje3 , welcome to the community!

The user’s metadata isn’t part of the OIDC standard claims, so the scopes requested will not return it - OpenID Connect Scopes

Therefore you would need to use an action to insert the user’s metadata into the ID token as a custom namespaced claim:

So you could have an Action like this (if there is a chance that metadata may not be present for certain users, I would recommend adding error handling / default values for these claims - whichever suits your use case better):

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://my-app.example.com';
  api.idToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user_metadata);
  api.idToken.setCustomClaim(`${namespace}/app_metadata`, event.user.app_metadata);
  }
}
2 Likes

Hy Sgo,
A big thanks for your response. All is right now.

Gilbert

1 Like

Glad to hear that! Teamwork makes the dreamwork!