# Add uuid as custom claim to accesstoken

**URL:** <https://community.auth0.com/t/add-uuid-as-custom-claim-to-accesstoken/73859>\
**Category:** Get Help\
**Tags:** jwt, actions, api, auth0\
**Created:** [November 27, 2021, 5:26pm UTC](https://community.auth0.com/t/add-uuid-as-custom-claim-to-accesstoken/73859 "2021-11-27T17:26:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![subee.admin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/subee.admin/32/33100_2.png) [@subee.admin](https://community.auth0.com/u/subee.admin)\
**Post date:** [November 27, 2021, 5:26pm UTC](https://community.auth0.com/t/add-uuid-as-custom-claim-to-accesstoken/73859/1 "2021-11-27T17:26:19Z")

</div>

Hi all!

I have one native application and an api. What I have configured is to authenticate user through the native application and using a login/post login action (which calls to get access token from the M2M application for the api), get the access token for the api.

What I am trying to accomplish is that, to set up an action for the M2M application to set a custom claim for users’ uuid that were added to app metadata/ user meta data in the previous login/post login actions. However, I found there is no access to user in the M2M action’s event object. How can I accomplish this?

---

<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:** [November 28, 2021, 11:51am UTC](https://community.auth0.com/t/add-uuid-as-custom-claim-to-accesstoken/73859/2 "2021-11-28T11:51:25Z")

</div>

Hi @subee.admin

Thanks for getting in touch with us here at Auth0 Community!

The M2M Action is based on the Client Credentials flow where a client id and client secret is used to authenticate the M2M application (typical for services running on the backend) and as a result there is no user authentication involved so the user property of the event object is out of scope, please see [https://auth0.com/docs/authorization/flows/client-credentials-flow](https://auth0.com/docs/authorization/flows/client-credentials-flow)

If you have a Native app I expect you will be using something like Authorization Code Flow with Proof Key for Code Exchange (PKCE) [https://auth0.com/docs/authorization/flows/authorization-code-flow-with-proof-key-for-code-exchange-pkce](https://auth0.com/docs/authorization/flows/authorization-code-flow-with-proof-key-for-code-exchange-pkce) when you authorise with this flow you will receive an ID Token and Access Token, you can use the Access Token received here for access to your API and maybe add your custom claims to the Token at this point [https://auth0.com/docs/security/tokens/access-tokens](https://auth0.com/docs/security/tokens/access-tokens)

I’m not sure what SDK you’re using but I would review the documentation to check how to do this [https://auth0.com/docs/libraries](https://auth0.com/docs/libraries) e.g. if you were using React Native you might do the following to get an ID Token and an Access Token.

```auto
auth0
    .webAuth
    .authorize({scope: 'openid profile email'})
    .then(credentials =>
      // Successfully authenticated
      // Store the accessToken
      this.setState({ accessToken: credentials.accessToken })
    )
    .catch(error => console.log(error));

```

Unless your use case is different, if so, please let us know what your use case is and how the M2M application fits into the picture.

Many thanks.

---

<div class="post-metadata">

**Author:** ![subee.admin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/subee.admin/32/33100_2.png) [@subee.admin](https://community.auth0.com/u/subee.admin)\
**Post date:** [November 30, 2021, 5:35pm UTC](https://community.auth0.com/t/add-uuid-as-custom-claim-to-accesstoken/73859/3 "2021-11-30T17:35:12Z")

</div>

Thanks for the quick and detailed reply! I don’t know how I missed the notification.

> when you authorise with this flow you will receive an ID Token and Access Token, you can use the Access Token received here for access to your API

Actually, I have already tried to use the access token from the native application to authorize the API but I got no success in that. The API would not accept the token (401 unauthorized error).

The application is built with Flutter and I have referenced [this](https://auth0.com/blog/get-started-with-flutter-authentication/) and [this](https://auth0.com/blog/flutter-authentication-authorization-with-auth0-part-1-adding-authentication-to-an-app/). I got the authentication working in the app (was able to login with google) but the access token somehow had invalid signature (checked on [jwt.io](http://jwt.io)).

It’s confusing because if any credentials or configuration was misconfigured I would not be able to login in the first place. Could you please give me an idea how to approach this?

---

<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:** [November 30, 2021, 7:24pm UTC](https://community.auth0.com/t/add-uuid-as-custom-claim-to-accesstoken/73859/4 "2021-11-30T19:24:49Z")

</div>

Hi @subee.admin

The guides appear to use opaque access tokens which are not in JWT format (I wouldn’t have thought these were readable on [jwt.io](http://jwt.io)) unless you have a custom API defined in your Auth0 dashboard with an identifier that you’re using as an audience value in your app, this will produce a token in JWT format (see [https://auth0.com/docs/security/tokens/access-tokens](https://auth0.com/docs/security/tokens/access-tokens)). If so, I would just ensure the identifier of this custom API and your audience value match exactly. If you were using the {YOUR\_AUTH0\_DOMAIN}/userinfo as the audience value then your access token will be an opaque string.

For more information about creating and configuring an API in Auth0, see: [https://auth0.com/docs/apis](https://auth0.com/docs/apis)

Otherwise, did you notice if there was anything off on [jwt.io](http://jwt.io)? access token expired perhaps?

I would also check the **OIDC Conformant** switch, located in the client’s advanced settings. See this for more info: [https://auth0.com/docs/api-auth/tutorials/adoption/oidc-conformant](https://auth0.com/docs/api-auth/tutorials/adoption/oidc-conformant)

Regards  
Saqib.

---

<div class="post-metadata">

**Author:** ![subee.admin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/subee.admin/32/33100_2.png) [@subee.admin](https://community.auth0.com/u/subee.admin)\
**Post date:** [November 30, 2021, 11:30pm UTC](https://community.auth0.com/t/add-uuid-as-custom-claim-to-accesstoken/73859/5 "2021-11-30T23:30:59Z")

</div>

OMG! I never thought it would generate opaque access token… Adding audience as an additional parameter was the key.

Thank you so much for your kind explanation!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 7, 2021, 2:26pm UTC](https://community.auth0.com/t/add-uuid-as-custom-claim-to-accesstoken/73859/6 "2021-12-07T14:26:07Z")

</div>

No worries! We’re here for you!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 7, 2021, 2:26pm UTC](https://community.auth0.com/t/add-uuid-as-custom-claim-to-accesstoken/73859/7 "2021-12-07T14:26:10Z")

</div>


