# Custom claims missing from tokens

**URL:** <https://community.auth0.com/t/custom-claims-missing-from-tokens/81425>\
**Category:** Get Help\
**Tags:** custom-claims\
**Created:** [April 8, 2022, 6:24am UTC](https://community.auth0.com/t/custom-claims-missing-from-tokens/81425 "2022-04-08T06:24:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![argo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/argo/32/24230_2.png) [@argo](https://community.auth0.com/u/argo)\
**Post date:** [April 8, 2022, 6:24am UTC](https://community.auth0.com/t/custom-claims-missing-from-tokens/81425/1 "2022-04-08T06:24:28Z")

</div>

Hi.

I am using a rule to add custom claims to tokens obtained using the **resource owner password flow.**

On two tenants, with identical app configurations, API configurations, rules and connections, one app obtains all custom claims, properly namespaced, and the other doesn’t.

I can’t seem to understand why this is happening. Is there a hidden grant I need to set?

Sample “stunted” jwt payload:

```auto
{
  "iss": "https://<xxx>.auth0.com/",
  "sub": "auth0|<xxx>",
  "aud": [
    "https://<xxx>.appspot.com/graphql",
    "https://<xxx>.auth0.com/userinfo"
  ],
  "iat": 1649396829,
  "exp": 1649483229,
  "azp": "<xxx>",
  "scope": "openid profile email offline_access",
  "gty": "password"
}

```

Sample valid token from the other tenant:

```auto
{
  "https://<namespace>/access": "ADMIN",
  "https://<namespace>/id": {},
  "https://<namespace>/memberNumber": {},
  "iss": "https://<xxx>.auth0.com/",
  "sub": "auth0|<xxx>",
  "aud": [
    "https://<xxx>.appspot.com/graphql",
    "https://<xxx>.auth0.com/userinfo"
  ],
  "iat": 1649397775,
  "exp": 1649484175,
  "azp": "<xxx>",
  "scope": "openid profile email offline_access",
  "gty": "password"
}

```

The rule is (abriged):

```auto
function (user, context, callback) {
  const namespaces = ['https://<xxx>'];
  namespaces.forEach(namespace => {
    user.app_metadata = user.app_metadata || {};
    context.idToken[namespace + '/access'] = user.app_metadata.access;
    context.accessToken[namespace + '/access'] = user.app_metadata.access;

    user.app_metadata.id = user.app_metadata.id || {};
    context.idToken[namespace + '/id'] = user.app_metadata.id;
    context.accessToken[namespace + '/id'] = user.app_metadata.id;

    // ...
  });
  callback(null, user, context);
}

```

Thank you in advance for guidelines and help.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 8, 2022, 4:25pm UTC](https://community.auth0.com/t/custom-claims-missing-from-tokens/81425/3 "2022-04-08T16:25:36Z")

</div>

Hi @argo,

I tested your rule, and everything worked okay for me, although I didn’t see a `memberNumber` claim as it’s not part of the rule you posted.

Make sure your namespace conforms to the [Create Custom Claims](https://auth0.com/docs/secure/tokens/json-web-tokens/create-namespaced-custom-claims) guidelines. Specifically, make sure it doesn’t include an Auth0 domain. You can try `https://test` to be safe.

---

<div class="post-metadata">

**Author:** ![argo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/argo/32/24230_2.png) [@argo](https://community.auth0.com/u/argo)\
**Post date:** [April 9, 2022, 8:25am UTC](https://community.auth0.com/t/custom-claims-missing-from-tokens/81425/4 "2022-04-09T08:25:28Z")

</div>

Hi @dan.woda , thank you for the reply.

The domain doesn’t include `auth0.com`. Like I said, the configuration is the same for both apps on two separate tenants, but everything just works fine on one tenant, while I don’t receive the custom claims for tokens on the other tenant.

I have tried every combination or permutation of settings I could think of. The only options left to investigate are adding some of the [extension grants](https://auth0.com/docs/get-started/applications/application-grant-types#auth0-extension-grants) that might be relevant, or recreating the app from scratch.

---

<div class="post-metadata">

**Author:** ![argo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/argo/32/24230_2.png) [@argo](https://community.auth0.com/u/argo)\
**Post date:** [April 21, 2022, 1:55pm UTC](https://community.auth0.com/t/custom-claims-missing-from-tokens/81425/5 "2022-04-21T13:55:37Z")

</div>

So: the issue here was squarely with me.

I had reproduced the rule on the production tenant incorrectly, and custom claims were only being added to the id token as a result.

Case closed as far as I am concerned.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 21, 2022, 3:16pm UTC](https://community.auth0.com/t/custom-claims-missing-from-tokens/81425/6 "2022-04-21T15:16:01Z")

</div>

Thanks for posting an update. Glad you figured it out!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [May 25, 2022, 9:34pm UTC](https://community.auth0.com/t/custom-claims-missing-from-tokens/81425/7 "2022-05-25T21:34:47Z")

</div>


