# Storing custom claims in Auth0 JWT?

**URL:** <https://community.auth0.com/t/storing-custom-claims-in-auth0-jwt/6523>\
**Category:** Get Help\
**Tags:** tier1, claims, jwt\
**Created:** [May 8, 2017, 10:54am UTC](https://community.auth0.com/t/storing-custom-claims-in-auth0-jwt/6523 "2017-05-08T10:54:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![account](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@account](https://community.auth0.com/u/account)\
**Post date:** [May 8, 2017, 10:54am UTC](https://community.auth0.com/t/storing-custom-claims-in-auth0-jwt/6523/1 "2017-05-08T10:54:47Z")

</div>

How do I store parts of user\_metadata in a custom claim inside auth0 JWT?

I added a rule which contains:

```
function (user, context, callback) {
   user.user_metadata = user.user_metadata || {};

   user.my_claim = user.my_claim || {};
   user.my_claim.firstName = user.user_metadata.firstName;
   user.my_claim.lastName = user.user_metadata.lastName;

   callback(null, user, context);
}

```

I also made sure that i’m passing `openid profile my_claim` in the scope parameter during logins. But the final JWT does not contain my\_claim JSON.

Been pulling my hair on this for hours. Could someone help me figure out what i’m missing?

---

<div class="post-metadata">

**Author:** ![bragma](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bragma/32/13310_2.png) [@bragma](https://community.auth0.com/u/bragma)\
**Post date:** [May 8, 2017, 3:53pm UTC](https://community.auth0.com/t/storing-custom-claims-in-auth0-jwt/6523/2 "2017-05-08T15:53:12Z")

</div>

This is what I am doing:

```
function (user, context, callback) {

  // If an access token is present, add a property to it
  if (context.accessToken) {
    var someproperty = user.someproperty || (user.app_metadata && user.app_metadata.someproperty);
    var namespace = 'https://myappapi.mycompany.com/';
    if (someproperty){
      context.accessToken[namespace + 'someproperty'] = someproperty;
    }
  }

  callback(null, user, context);
}

```

---

<div class="post-metadata">

**Author:** ![account](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@account](https://community.auth0.com/u/account)\
**Post date:** [May 9, 2017, 1:38am UTC](https://community.auth0.com/t/storing-custom-claims-in-auth0-jwt/6523/3 "2017-05-09T01:38:45Z")

</div>

This is somewhat interesting. I’ve never seen this done anywhere and most of the stuff that I do see simply adds the property to the user object which has to match one of the scopes passed in. At least this is what I’m reading from Auth0 devs which does not work. Is there a reason why you’re prefixing property name with a URL?

---

<div class="post-metadata">

**Author:** ![prashantT](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/prashantt/32/6002_2.png) [@prashantT](https://community.auth0.com/u/prashantT)\
**Post date:** [May 9, 2017, 7:48am UTC](https://community.auth0.com/t/storing-custom-claims-in-auth0-jwt/6523/4 "2017-05-09T07:48:10Z")

</div>

@account This is based on our new flows that aim to make our tokens more aligned with the OIDC specifications. The documentation for the namespaced claims is here: [OpenID Connect Scopes](https://auth0.com/docs/api-auth/tutorials/adoption/scope-custom-claims)

---

<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 2, 2018, 5:53am UTC](https://community.auth0.com/t/storing-custom-claims-in-auth0-jwt/6523/5 "2018-03-02T05:53:45Z")

</div>


