# App\_metadata not being returned in token from /oauth/token even though rule exists

**URL:** <https://community.auth0.com/t/app-metadata-not-being-returned-in-token-from-oauth-token-even-though-rule-exists/56970>\
**Category:** Get Help\
**Created:** [January 28, 2021, 4:47pm UTC](https://community.auth0.com/t/app-metadata-not-being-returned-in-token-from-oauth-token-even-though-rule-exists/56970 "2021-01-28T16:47:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard.sanigar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/richard.sanigar/32/23147_2.png) [@richard.sanigar](https://community.auth0.com/u/richard.sanigar)\
**Post date:** [January 28, 2021, 4:47pm UTC](https://community.auth0.com/t/app-metadata-not-being-returned-in-token-from-oauth-token-even-though-rule-exists/56970/1 "2021-01-28T16:47:35Z")

</div>

Hi

I’m creating a JMETER test inside a gitlab pipeline, the domain I am testing takes a JWT in the Authorisation Header (Bearer) in the request.

I’m using the following curl command to authenticate and get a token back:

curl --request POST   
–url ‘[https://gotham-city-dev.eu.auth0.com/oauth/token](https://gotham-city-dev.eu.auth0.com/oauth/token)’   
–header ‘content-type: application/x-www-form-urlencoded’   
–data ‘grant\_type=password’   
–data ‘username=BruceWayne’   
–data ‘password=BatMan123’   
–data ‘audience=[https://gotham-city-dev.eu.auth0.com/api/v2/](https://gotham-city-dev.eu.auth0.com/api/v2/)’   
–data ‘scope=read:current\_user’   
–data ‘client\_id=fMHp…MHho’   
–data ‘client\_secret=3b-joVidd…dibANvI’

And I have the following rule set up to add app\_metadata to the token:

function (user, context, callback) {  
const namespace = ‘[https://gotham-city.com/](https://gotham-city.com/)’;  
context.idToken[namespace + ‘authorities’] = user.app\_metadata.roles;  
context.idToken[namespace + ‘locale’] = user.app\_metadata.itc\_locale.toUpperCase();  
context.idToken[namespace + ‘user\_name’] = user.user\_name;  
callback(null, user, context);  
}

A token is returned minus the rule controlled app\_metadata. What am I missing or why is it ignoring the rule?

Any ideas will be greatly appreciated.

Regards

Richard

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [January 28, 2021, 8:19pm UTC](https://community.auth0.com/t/app-metadata-not-being-returned-in-token-from-oauth-token-even-though-rule-exists/56970/3 "2021-01-28T20:19:15Z")

</div>

Hi @richard.sanigar,

Try updating your rule to add the metadata to the Access Token instead of the ID Token.

```auto
function (user, context, callback) {
  const namespace = ‘https://gotham-city.com/’;
  context.accessToken[namespace + ‘authorities’] = user.app_metadata.roles;
  context.accessToken[namespace + ‘locale’] = user.app_metadata.itc_locale.toUpperCase();
  context.accessToken[namespace + ‘user_name’] = user.user_name;
  callback(null, user, context);
}

```

Unlike the Authorization Code flow, the [Resource Owner Password](https://auth0.com/docs/flows/resource-owner-password-flow) flow only passes an Access Token and not an ID Token.

---

<div class="post-metadata">

**Author:** ![richard.sanigar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/richard.sanigar/32/23147_2.png) [@richard.sanigar](https://community.auth0.com/u/richard.sanigar)\
**Post date:** [January 28, 2021, 10:19pm UTC](https://community.auth0.com/t/app-metadata-not-being-returned-in-token-from-oauth-token-even-though-rule-exists/56970/4 "2021-01-28T22:19:02Z")

</div>

> [@stephanie.chamblee](#):
>
> ```auto
> context.accessToken[namespace + ‘authorities’] = user.app_metadata.roles;
> context.accessToken[namespace + ‘locale’] = user.app_metadata.itc_locale.toUpperCase();
> context.accessToken[namespace + ‘user_name’] = user.user_name;
> 
> ```

Wow, thank you Stephanie, that has helped a lot  
Kind regards  
Richard

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [January 29, 2021, 12:15pm UTC](https://community.auth0.com/t/app-metadata-not-being-returned-in-token-from-oauth-token-even-though-rule-exists/56970/5 "2021-01-29T12:15:32Z")

</div>

Glad to hear that helped!

---

<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:** [February 13, 2021, 12:15pm UTC](https://community.auth0.com/t/app-metadata-not-being-returned-in-token-from-oauth-token-even-though-rule-exists/56970/6 "2021-02-13T12:15:35Z")

</div>

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