# Extract user\_metadata & app\_metadata

**URL:** <https://community.auth0.com/t/extract-user-metadata-app-metadata/71565>\
**Category:** Get Help\
**Tags:** jwt\
**Created:** [October 19, 2021, 7:53am UTC](https://community.auth0.com/t/extract-user-metadata-app-metadata/71565 "2021-10-19T07:53:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gheintje3](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gheintje3/32/32409_2.png) [@gheintje3](https://community.auth0.com/u/gheintje3)\
**Post date:** [October 19, 2021, 7:53am UTC](https://community.auth0.com/t/extract-user-metadata-app-metadata/71565/1 "2021-10-19T07:53:27Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [October 19, 2021, 2:36pm UTC](https://community.auth0.com/t/extract-user-metadata-app-metadata/71565/2 "2021-10-19T14:36:54Z")

</div>

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](https://auth0.com/docs/configure/apis/scopes/openid-connect-scopes#standard-claims)

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

- [Login Flow](https://auth0.com/docs/actions/triggers/post-login)
- [Create Custom Claims](https://auth0.com/docs/security/tokens/json-web-tokens/create-namespaced-custom-claims)

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

```auto
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);
  }
}
```

---

<div class="post-metadata">

**Author:** ![gheintje3](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gheintje3/32/32409_2.png) [@gheintje3](https://community.auth0.com/u/gheintje3)\
**Post date:** [October 20, 2021, 4:34pm UTC](https://community.auth0.com/t/extract-user-metadata-app-metadata/71565/3 "2021-10-20T16:34:15Z")

</div>

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

Gilbert

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [October 28, 2021, 12:53pm UTC](https://community.auth0.com/t/extract-user-metadata-app-metadata/71565/4 "2021-10-28T12:53:26Z")

</div>

Glad to hear that! Teamwork makes the dreamwork!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [October 28, 2021, 12:53pm UTC](https://community.auth0.com/t/extract-user-metadata-app-metadata/71565/5 "2021-10-28T12:53:31Z")

</div>


