# Retrieving app\_metadata section from the user once logged in

**URL:** <https://community.auth0.com/t/retrieving-app-metadata-section-from-the-user-once-logged-in/128797>\
**Category:** Get Help\
**Tags:** extensibility\
**Created:** [March 3, 2024, 3:24pm UTC](https://community.auth0.com/t/retrieving-app-metadata-section-from-the-user-once-logged-in/128797 "2024-03-03T15:24:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rosario.martone.uk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rosario.martone.uk/32/55342_2.png) [@rosario.martone.uk](https://community.auth0.com/u/rosario.martone.uk)\
**Post date:** [March 3, 2024, 3:24pm UTC](https://community.auth0.com/t/retrieving-app-metadata-section-from-the-user-once-logged-in/128797/1 "2024-03-03T15:24:32Z")

</div>

Hi,  
I successfully deployed MAUI application to my devices and authenticating with Auth0 works on both IOS/Android platforms. I was wondering what is the best way to retrieve additional sections fromt the user, such as app\_metadata where I am adding the roles for the user.  
I am a C# developer and any help on this topicwould be much appreciated, thanks!

Ross.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [March 5, 2024, 10:19pm UTC](https://community.auth0.com/t/retrieving-app-metadata-section-from-the-user-once-logged-in/128797/3 "2024-03-05T22:19:41Z")

</div>

Hey there @rosario.martone.uk welcome to the community!

> [@rosario.martone.uk](#):
>
> I was wondering what is the best way to retrieve additional sections fromt the user, such as app\_metadata where I am adding the roles for the user.

The most effective way is probably to add the metadata to tokens and go about it that way - You need to add the metadata as a custom claim(s) using an action:

[https://community.auth0.com/t/adding-custom-claims-to-tokens/84590](https://community.auth0.com/t/adding-custom-claims-to-tokens/84590)

An example might look like:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://myapp.example.com';
  const { favorite_color, preferred_contact } = event.user.user_metadata;

  if (event.authorization) {
    // Set claims 
    api.idToken.setCustomClaim(`${namespace}/favorite_color`, favorite_color);
    api.idToken.setCustomClaim(`${namespace}/preferred_contact`, preferred_contact);
  }
};

```

---

<div class="post-metadata">

**Author:** ![rosario.martone.uk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rosario.martone.uk/32/55342_2.png) [@rosario.martone.uk](https://community.auth0.com/u/rosario.martone.uk)\
**Post date:** [March 6, 2024, 6:47am UTC](https://community.auth0.com/t/retrieving-app-metadata-section-from-the-user-once-logged-in/128797/4 "2024-03-06T06:47:19Z")

</div>

Hi,  
thanks for this example. This is exactly what I did but it still not working.

Response from userinfo:  
{  
“nickname”: “rosario.martone”,  
“name”: “[rosario.martone@gmail.com](mailto:rosario.martone@gmail.com)”,  
“picture”: “[https://s.gravatar.com/avatar/7c988bb6e283c264a5a85fa0ba979820?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fro.png](https://s.gravatar.com/avatar/7c988bb6e283c264a5a85fa0ba979820?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fro.png)”,  
“updated\_at”: “2024-03-06T06:43:19.5Z”,  
“iss”: “[https://dev-70vjf83lo03hdc1r.uk.auth0.com/](https://dev-70vjf83lo03hdc1r.uk.auth0.com/)”,  
“aud”: “7zJzL2KUozIiltrFXgpSVWjbGp0lU5mh”,  
“iat”: 1709707400,  
“exp”: 1709743400,  
“sub”: “auth0|65e42f567c644203f3b666d7”,  
“sid”: “p7eXDj8p7YQnQHBFQ2m4HEa9lBUM2z9r”  
}

This is the user\_metadata section on the Auth0 user:  
{  
“roles”: “admin”  
}

This is the custom function I have added to the login process:  
/\*\*

- Handler that will be called during the execution of a PostLogin flow.

- 
- @param {Event} event - Details about the user and the context in which they are logging in.

- @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.  
\*/  
exports.onExecutePostLogin = async (event, api) =\> {  
const namespace = ‘[https://dev-70vjf83lo03hdc1r.uk.auth0.com](https://dev-70vjf83lo03hdc1r.uk.auth0.com)’;  
const { roles } = event.user.user\_metadata;

I have no idea what else I can try orwhere I am mistaken, any help would be much appreciated!

Thanks,  
Ross.

---

<div class="post-metadata">

**Author:** ![rosario.martone.uk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rosario.martone.uk/32/55342_2.png) [@rosario.martone.uk](https://community.auth0.com/u/rosario.martone.uk)\
**Post date:** [March 6, 2024, 6:52am UTC](https://community.auth0.com/t/retrieving-app-metadata-section-from-the-user-once-logged-in/128797/5 "2024-03-06T06:52:20Z")

</div>

Also, this is the scope I have tried, not sure it’s correct:

Scope = “openid profile read:current\_user”

---

<div class="post-metadata">

**Author:** ![rosario.martone.uk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rosario.martone.uk/32/55342_2.png) [@rosario.martone.uk](https://community.auth0.com/u/rosario.martone.uk)\
**Post date:** [March 6, 2024, 6:57am UTC](https://community.auth0.com/t/retrieving-app-metadata-section-from-the-user-once-logged-in/128797/6 "2024-03-06T06:57:15Z")

</div>

I also have tried this: [Auth0: how to include app\_metadata in user info](https://phillcode.io/auth0-how-to-include-appmetadata-in-user-info)  
I ran out of ideas! 🙂

Ross

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [March 6, 2024, 11:37pm UTC](https://community.auth0.com/t/retrieving-app-metadata-section-from-the-user-once-logged-in/128797/7 "2024-03-06T23:37:33Z")

</div>

Thanks for following up!

It might be due to the fact that you’re using an `auth0` domain as your namespace which isn’t allowed:

> **[Create Custom Claims](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#namespaced-guidelines)**
>
> Learn how to create collision-resistant names for custom claims.

---

<div class="post-metadata">

**Author:** ![rosario.martone.uk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rosario.martone.uk/32/55342_2.png) [@rosario.martone.uk](https://community.auth0.com/u/rosario.martone.uk)\
**Post date:** [March 7, 2024, 8:18am UTC](https://community.auth0.com/t/retrieving-app-metadata-section-from-the-user-once-logged-in/128797/8 "2024-03-07T08:18:01Z")

</div>

Hi,  
That was exactly the issue and you saved my day.

Cheers,  
Ross

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [March 8, 2024, 11:18pm UTC](https://community.auth0.com/t/retrieving-app-metadata-section-from-the-user-once-logged-in/128797/9 "2024-03-08T23:18:02Z")

</div>

Awesome, glad to hear that resolved it - Thanks for confirming!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 22, 2024, 11:18pm UTC](https://community.auth0.com/t/retrieving-app-metadata-section-from-the-user-once-logged-in/128797/10 "2024-03-22T23:18:20Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
