# Is there a way to update the m2m access token so that the scopes are an array rather than a string

**URL:** <https://community.auth0.com/t/is-there-a-way-to-update-the-m2m-access-token-so-that-the-scopes-are-an-array-rather-than-a-string/93533>\
**Category:** JWT.io\
**Tags:** m2m, jwt, scopes\
**Created:** [November 1, 2022, 9:26pm UTC](https://community.auth0.com/t/is-there-a-way-to-update-the-m2m-access-token-so-that-the-scopes-are-an-array-rather-than-a-string/93533 "2022-11-01T21:26:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul10](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/paul10/32/33718_2.png) [@paul10](https://community.auth0.com/u/paul10)\
**Post date:** [November 1, 2022, 9:26pm UTC](https://community.auth0.com/t/is-there-a-way-to-update-the-m2m-access-token-so-that-the-scopes-are-an-array-rather-than-a-string/93533/1 "2022-11-01T21:26:33Z")

</div>

This is related to this request which I saw was closed - [Change the scope from string to array format in access token](https://community.auth0.com/t/change-the-scope-from-string-to-array-format-in-access-token/91125). I have the same issue and was wondering if there is a way. We have an integration partner who requires the scopes to be an array rather than a string.

To be clear scopes in the m2m access token look like this:

`"scope": "scope1 scope2"`

We need them to look like this

```auto
"scope": [
  "scope1",
  "scope2"
]

```

---

<div class="post-metadata">

**Author:** ![paul10](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/paul10/32/33718_2.png) [@paul10](https://community.auth0.com/u/paul10)\
**Post date:** [November 1, 2022, 9:28pm UTC](https://community.auth0.com/t/is-there-a-way-to-update-the-m2m-access-token-so-that-the-scopes-are-an-array-rather-than-a-string/93533/2 "2022-11-01T21:28:09Z")

</div>

@ty.frith I saw you commented on the original issue. Is this impossible or is there a way forward?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [November 1, 2022, 10:17pm UTC](https://community.auth0.com/t/is-there-a-way-to-update-the-m2m-access-token-so-that-the-scopes-are-an-array-rather-than-a-string/93533/3 "2022-11-01T22:17:21Z")

</div>

Hey @paul10 welcome to the community!

> [@paul10](#):
>
> I saw you commented on the original issue. Is this impossible or is there a way forward?

It’s not currently possible AFAIK, but what’s the use case? I’m curious as to why you need scopes in an array. I’d just love a use case so I can bounce ideas off folks internally 🙂

Let me know!

---

<div class="post-metadata">

**Author:** ![paul10](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/paul10/32/33718_2.png) [@paul10](https://community.auth0.com/u/paul10)\
**Post date:** [November 2, 2022, 12:04pm UTC](https://community.auth0.com/t/is-there-a-way-to-update-the-m2m-access-token-so-that-the-scopes-are-an-array-rather-than-a-string/93533/5 "2022-11-02T12:04:36Z")

</div>

Hi @ty.frith thanks for responding. We have an integration partner who is leveraging the JWT bearer flow for authentication to their api. We need to generate a JWT and pass it to them and they will respond with a bearer token we can use to make subsequent calls. They have some specific requirements for the JWT, one being that the scope attribute needs to be an array rather than a string. We were hoping to use Auth0’s M2M solution rather than generating and signing our own JWTs. Would it be possible to use a client credentials hook to change the datatype of the scope attribute to an array?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [November 3, 2022, 7:06pm UTC](https://community.auth0.com/t/is-there-a-way-to-update-the-m2m-access-token-so-that-the-scopes-are-an-array-rather-than-a-string/93533/6 "2022-11-03T19:06:39Z")

</div>

No problem @paul10 happy to help where I can!

Thanks for describing the use case, very helpful - I’m curious if there is any way for the consuming service to accept a value other than `scope`? My thinking is that you could write an [Action](https://auth0.com/docs/customize/actions/flows-and-triggers/machine-to-machine-flow) for the client credentials exchange that would add a custom claim with the value of `event.transaction.requested_scopes` of the [event object](https://auth0.com/docs/customize/actions/flows-and-triggers/machine-to-machine-flow/event-object) which will provide you with an array of the scopes requested. You would need to request the scopes explicitly in the request to `/oauth/token`, and they must be granted to the m2m at the API level in Auth0.

The request might look like:

```auto
curl --request POST \
  --url https://tenant_domain.us.auth0.com/oauth/token \
  --header 'content-type: application/json' \
  --data '{"client_id":"XXX","client_secret":"XXX", "scope": "read:appointments read:prescriptions create:appointments read:msg delete:appointments","audience":"https://test-api-endpoint","grant_type":"client_credentials"}'

```

Action:

```auto
exports.onExecuteCredentialsExchange = async (event, api) => {
  api.accessToken.setCustomClaim("scopes_array", event.transaction.requested_scopes);  
};

```

Resulting JWT:

```auto
{
  "scopes_array": [
    "read:appointments",
    "read:prescriptions",
    "create:appointments",
    "read:msg",
    "delete:appointments"
  ],
  "iss": "https://tenant_domain.us.auth0.com/",
  "sub": "PpSYjwerwer34535eE9Oxvu0s69O730d@clients",
  "aud": "https://test-api-endpoint",
  "iat": 1667497853,
  "exp": 1667584253,
  "azp": "PpSYjfy2yw87678QheE9Oxvu0s69O730d",
  "scope": "read:appointments read:prescriptions create:appointments delete:appointments read:msg",
  "gty": "client-credentials"
}

```

Let me know what you think!

---

<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:** [December 22, 2022, 11:53pm UTC](https://community.auth0.com/t/is-there-a-way-to-update-the-m2m-access-token-so-that-the-scopes-are-an-array-rather-than-a-string/93533/7 "2022-12-22T23:53:00Z")

</div>

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