# Unable to add custom claim to access token using custom action

**URL:** <https://community.auth0.com/t/unable-to-add-custom-claim-to-access-token-using-custom-action/97284>\
**Category:** Get Help\
**Tags:** grants, management-api\
**Created:** [January 1, 2023, 9:45am UTC](https://community.auth0.com/t/unable-to-add-custom-claim-to-access-token-using-custom-action/97284 "2023-01-01T09:45:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![benmsullivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/benmsullivan/32/42226_2.png) [@benmsullivan](https://community.auth0.com/u/benmsullivan)\
**Post date:** [January 1, 2023, 9:45am UTC](https://community.auth0.com/t/unable-to-add-custom-claim-to-access-token-using-custom-action/97284/1 "2023-01-01T09:45:53Z")

</div>

Hi

I am trying to add a custom claim to my access tokens using a custom action:

````auto
exports.onExecutePostLogin = async (event, api) => {
  // This adds the authenticated user's email address to the access token.
  if (event.authorization) {
    const namespace = 'https://foo.com';
    api.accessToken.setCustomClaim(`${namespace}/claims/userId`, event.user.user_id);
  }
};```

I retrieve an access token using the new PKCE grant type for OAuth 2.0 Authorisation in Postman 10.6.7

I am getting an access token back but the payload is empty.

Any ideas on what I'm doing wrong?

Thanks
````

---

<div class="post-metadata">

**Author:** ![SaqibHussain](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/saqibhussain/32/42924_2.png) [@SaqibHussain](https://community.auth0.com/u/SaqibHussain)\
**Post date:** [January 1, 2023, 11:34am UTC](https://community.auth0.com/t/unable-to-add-custom-claim-to-access-token-using-custom-action/97284/2 "2023-01-01T11:34:46Z")

</div>

Hi @benmsullivan

Thanks for getting in touch with us at Auth0 Community.

If the payload is empty please ensure you are including an audience as part of your /authorize for PKCE e.g.

```auto
https://YOUR_DOMAIN/authorize?
    response_type=code&
    code_challenge={codeChallenge}&
    code_challenge_method=S256&
    client_id=YOUR_CLIENT_ID&
    redirect_uri={yourCallbackUrl}&
    scope=SCOPE&
    audience={apiAudience}

```

[https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow-with-pkce#example-authorization-url](https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-authorization-code-flow-with-pkce#example-authorization-url)

Warm regards.

---

<div class="post-metadata">

**Author:** ![benmsullivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/benmsullivan/32/42226_2.png) [@benmsullivan](https://community.auth0.com/u/benmsullivan)\
**Post date:** [January 1, 2023, 11:49am UTC](https://community.auth0.com/t/unable-to-add-custom-claim-to-access-token-using-custom-action/97284/3 "2023-01-01T11:49:49Z")

</div>

Hi @SaqibHussain

I have added the client id as the audience in the Postman config but I still don’t see the custom claim on the access token…

---

<div class="post-metadata">

**Author:** ![SaqibHussain](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/saqibhussain/32/42924_2.png) [@SaqibHussain](https://community.auth0.com/u/SaqibHussain)\
**Post date:** [January 1, 2023, 12:02pm UTC](https://community.auth0.com/t/unable-to-add-custom-claim-to-access-token-using-custom-action/97284/4 "2023-01-01T12:02:56Z")

</div>

Hi @benmsullivan

The audience needs to be the api identifier i.e. the target for the access token, it will be a uri please see this community post for more info [https://community.auth0.com/t/what-is-the-audience/71414](https://community.auth0.com/t/what-is-the-audience/71414)

Warm regards.

---

<div class="post-metadata">

**Author:** ![benmsullivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/benmsullivan/32/42226_2.png) [@benmsullivan](https://community.auth0.com/u/benmsullivan)\
**Post date:** [January 1, 2023, 12:15pm UTC](https://community.auth0.com/t/unable-to-add-custom-claim-to-access-token-using-custom-action/97284/5 "2023-01-01T12:15:40Z")

</div>

Thanks @SaqibHussain

So I created a new API (was wondering what that was for) and set the audience config in postman to the URI configured in the Auth0 API audience field.

Still no custom claim in access token ☹

---

<div class="post-metadata">

**Author:** ![benmsullivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/benmsullivan/32/42226_2.png) [@benmsullivan](https://community.auth0.com/u/benmsullivan)\
**Post date:** [January 1, 2023, 12:20pm UTC](https://community.auth0.com/t/unable-to-add-custom-claim-to-access-token-using-custom-action/97284/6 "2023-01-01T12:20:40Z")

</div>

What grant types do I need on my application for PKCE? I only have Authorisation Code switched on as I don’t want to issue refresh tokens…

---

<div class="post-metadata">

**Author:** ![benmsullivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/benmsullivan/32/42226_2.png) [@benmsullivan](https://community.auth0.com/u/benmsullivan)\
**Post date:** [January 1, 2023, 12:30pm UTC](https://community.auth0.com/t/unable-to-add-custom-claim-to-access-token-using-custom-action/97284/7 "2023-01-01T12:30:34Z")

</div>

Just also wondering why there are no claims at all in the access token payload? Shouldn’t “sub” be in there?

---

<div class="post-metadata">

**Author:** ![SaqibHussain](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/saqibhussain/32/42924_2.png) [@SaqibHussain](https://community.auth0.com/u/SaqibHussain)\
**Post date:** [January 1, 2023, 1:08pm UTC](https://community.auth0.com/t/unable-to-add-custom-claim-to-access-token-using-custom-action/97284/8 "2023-01-01T13:08:44Z")

</div>

Hi @benmsullivan

Yes should be some claims unless your access token is still opaque which is shouldn’t be if you included an audience in your /authorize request, see my test below:

[https://your-domain/authorize](https://your-domain/authorize)?  
response\_type=code&  
code\_challenge=DNfupk731FmSqmTiRooflxhiOx9Ag6NrpLJUGqofX3s&  
code\_challenge\_method=S256&  
client\_id=yvGWLFsJ06nWfQO4VfbRpeweT8IY3SmA&  
redirect\_uri=[https://jwt.io](https://jwt.io)&  
scope=openid%20profile%20email&  
audience=[http://myapi.com/api](http://myapi.com/api)

---

<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:** [January 24, 2023, 4:51pm UTC](https://community.auth0.com/t/unable-to-add-custom-claim-to-access-token-using-custom-action/97284/9 "2023-01-24T16:51:47Z")

</div>

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