# setCustomClaim doesn't seem to work

**URL:** <https://community.auth0.com/t/setcustomclaim-doesnt-seem-to-work/93882>\
**Category:** Get Help\
**Tags:** extensibility, actions-extensibility\
**Created:** [November 7, 2022, 10:21pm UTC](https://community.auth0.com/t/setcustomclaim-doesnt-seem-to-work/93882 "2022-11-07T22:21:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dudo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dudo/32/40718_2.png) [@dudo](https://community.auth0.com/u/dudo)\
**Post date:** [November 7, 2022, 10:21pm UTC](https://community.auth0.com/t/setcustomclaim-doesnt-seem-to-work/93882/1 "2022-11-07T22:21:18Z")

</div>

```plaintext
exports.onExecuteCredentialsExchange = async (event, api) => {
  api.accessToken.setCustomClaim("person_id", event.client.metadata.uuid )
};

```

I’m trying to add a key to the token used for API calls. I’m using the code above within this simple flow:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/c/3/c3775a6be0b3077ca723540638ed8ac3a663c697.png)

The token passed to my server does **not** have `person_id`, though. Feels like I’m close, here…

---

<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:** [November 8, 2022, 4:54pm UTC](https://community.auth0.com/t/setcustomclaim-doesnt-seem-to-work/93882/3 "2022-11-08T16:54:59Z")

</div>

Hi @dudo,

Can you try using a [namespaced claim](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#namespaced-guidelines) to see if that is the problem?

You may also need to toggle on non-namespaced custom claims (we are currently working through a [migration](https://auth0.com/docs/troubleshoot/product-lifecycle/deprecations-and-migrations/custom-claims-migration)).

---

<div class="post-metadata">

**Author:** ![dudo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dudo/32/40718_2.png) [@dudo](https://community.auth0.com/u/dudo)\
**Post date:** [November 8, 2022, 5:31pm UTC](https://community.auth0.com/t/setcustomclaim-doesnt-seem-to-work/93882/4 "2022-11-08T17:31:48Z")

</div>

Tried this:

```plaintext
exports.onExecuteCredentialsExchange = async (event, api) => {
  const namespace = "https://app.compada.io"
  api.accessToken.setCustomClaim(`${namespace}/person_id`, event.client.metadata.uuid )
};

```

Nothing…

Just to be clear, `onExecuteCredentialsExchange` is where I get a token via `getAccessTokenSilently`, yes?

Also, I don’t see that migration in my dev tenant

 ![image](https://global.discourse-cdn.com/auth0/original/3X/7/6/769df5f375938ff39ac890152e941b143bf0cae4.png)

---

<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:** [November 8, 2022, 5:44pm UTC](https://community.auth0.com/t/setcustomclaim-doesnt-seem-to-work/93882/5 "2022-11-08T17:44:08Z")

</div>

> [@dudo](#):
>
> Just to be clear, `onExecuteCredentialsExchange` is where I get a token via `getAccessTokenSilently`, yes?

No, I didn’t catch that. This is likely the issue. You are **not** making a client credentials request when you are using getAccessTokenSilently.

You should use a [Login Flow](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow) Action instead.

---

<div class="post-metadata">

**Author:** ![dudo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dudo/32/40718_2.png) [@dudo](https://community.auth0.com/u/dudo)\
**Post date:** [November 8, 2022, 5:49pm UTC](https://community.auth0.com/t/setcustomclaim-doesnt-seem-to-work/93882/6 "2022-11-08T17:49:12Z")

</div>

I also tried that, with no success… w/ and w/o namespacing.

```plaintext
exports.onExecutePostLogin = async (event, api) => {
  const namespace = "https://app.compada.io"
  api.idToken.setCustomClaim(`${namespace}/person_id`, event.user.app_metadata.uuid);
};

```

I don’t _love_ how the api to get a handle on the token is different… or am I calling that incorrectly?

---

<div class="post-metadata">

**Author:** ![dudo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dudo/32/40718_2.png) [@dudo](https://community.auth0.com/u/dudo)\
**Post date:** [November 8, 2022, 6:13pm UTC](https://community.auth0.com/t/setcustomclaim-doesnt-seem-to-work/93882/7 "2022-11-08T18:13:03Z")

</div>

`api.accessToken` not `api.idToken`. We’re good! Thank you, @dan.woda

---

<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:** [November 8, 2022, 6:13pm UTC](https://community.auth0.com/t/setcustomclaim-doesnt-seem-to-work/93882/8 "2022-11-08T18:13:40Z")

</div>

Glad we figured it out! Cheers!

---

<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:** [November 22, 2022, 6:13pm UTC](https://community.auth0.com/t/setcustomclaim-doesnt-seem-to-work/93882/9 "2022-11-22T18:13:42Z")

</div>

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