# How to add application metadata under rule?

**URL:** <https://community.auth0.com/t/how-to-add-application-metadata-under-rule/80790>\
**Category:** Get Help\
**Tags:** rules, auth0\
**Created:** [March 30, 2022, 10:28am UTC](https://community.auth0.com/t/how-to-add-application-metadata-under-rule/80790 "2022-03-30T10:28:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![selvi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/selvi/32/33945_2.png) [@selvi](https://community.auth0.com/u/selvi)\
**Post date:** [March 30, 2022, 10:28am UTC](https://community.auth0.com/t/how-to-add-application-metadata-under-rule/80790/1 "2022-03-30T10:28:28Z")

</div>

1. Created Native application from Dashboard under Application
2. Added key value pair under application metadata(Name:OrgA)
3. How to add rule to fetch metadata under rule? So that I can view the application metadata while parsing the access token using jwt.  
Note: Already defined rule to fetch users roles and permission. How do I differentiate the rule belongs to user and application oriented? If I am using multiple rules means, how do I specify which rule belongs to which one?

---

<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 31, 2022, 12:04am UTC](https://community.auth0.com/t/how-to-add-application-metadata-under-rule/80790/3 "2022-03-31T00:04:44Z")

</div>

Hi there @selvi !

> [@selvi](#):
>
> How to add rule to fetch metadata under rule? So that I can view the application metadata while parsing the access token using jwt.

You can add application and/or user metadata to your user’s id/access token by adding a [custom claim](https://auth0.com/docs/secure/tokens/json-web-tokens/create-namespaced-custom-claims). You can accomplish this with either a rule:

```auto
function (user, context, callback) {
  // TODO: implement your rule
  const namespace = 'https://myapp.example.com';
  	context.idToken[namespace + '/user_metadata'] = user.user_metadata;
  	context.idToken[namespace + '/app_metadata'] = context.clientMetadata;
  return callback(null, user, context);
}

```

Or action (post login):

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

```

> [@selvi](#):
>
> How do I differentiate the rule belongs to user and application oriented? If I am using multiple rules means, how do I specify which rule belongs to which one?

I’m not 100% clear on what you mean here, but you could create a separate rule to add metadata - How you namespace the claim is also entirely up to you as well.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![selvi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/selvi/32/33945_2.png) [@selvi](https://community.auth0.com/u/selvi)\
**Post date:** [March 31, 2022, 4:34am UTC](https://community.auth0.com/t/how-to-add-application-metadata-under-rule/80790/4 "2022-03-31T04:34:57Z")

</div>

Thanks it’s working  
context.clientMetadata = context.clientMetadata || {};  
console.log(context.clientMetadata);  
context.idToken[namespace + ‘/app\_metadata’] = context.clientMetadata;  
context.accessToken[namespace + ‘/app\_metadata’] = context.clientMetadata;

---

<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:** [April 22, 2022, 9:54pm UTC](https://community.auth0.com/t/how-to-add-application-metadata-under-rule/80790/5 "2022-04-22T21:54:16Z")

</div>


