# Migrating M2M hook with custom response to actions

**URL:** <https://community.auth0.com/t/migrating-m2m-hook-with-custom-response-to-actions/124829>\
**Category:** Get Help\
**Tags:** custom-webtasks, deprecations\
**Created:** [January 15, 2024, 11:56am UTC](https://community.auth0.com/t/migrating-m2m-hook-with-custom-response-to-actions/124829 "2024-01-15T11:56:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicolaj.vinholt](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nicolaj.vinholt/32/53939_2.png) [@nicolaj.vinholt](https://community.auth0.com/u/nicolaj.vinholt)\
**Post date:** [January 15, 2024, 11:56am UTC](https://community.auth0.com/t/migrating-m2m-hook-with-custom-response-to-actions/124829/1 "2024-01-15T11:56:06Z")

</div>

We are in the final stages of moving all our hooks to actions, and have just one line remaining on clients credentials exchange. In this hook we modify the response to include the scope, which is currently relied on for our backend application(s):

```auto
module.exports = function(client, scope, audience, context, cb) {
  var access_token = { scope: scope };
  cb(null, access_token);
};

```

However I don’t see a way to replicate this exact functionality in actions, given it doesn’t seem to give you much flexibility in modifying the return value of the clients credentials exchange.  
Of course we can find another solution, but I am just wondering if there is an actions-native way of supporting this?

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [January 16, 2024, 10:12am UTC](https://community.auth0.com/t/migrating-m2m-hook-with-custom-response-to-actions/124829/3 "2024-01-16T10:12:35Z")

</div>

Hey there @nicolaj.vinholt , welcome to the Auth0 Community!

Do you intend to adjust scopes per request basis?

> [@nicolaj.vinholt](#):
>
> Of course we can find another solution, but I am just wondering if there is an actions-native way of supporting this?

Actions on that matter are still in it’s initial stages, but I can see two properties that seems to be relevant here (or at least approximately relevant):

`event.request.body` - params (also custom) that are sent with the credentials exchange flow; can contain for example the adjusted\_scopes param;

and

`api.accessToken.setCustomClaim` - currently this is the only callable [method](https://auth0.com/docs/customize/actions/flows-and-triggers/machine-to-machine-flow/api-object) to request changes to the access token being issued.

I crafted a short Action script that, within a custom claim of the issued access token, would give your backend app info about the adjusted scopes:

```auto
exports.onExecuteCredentialsExchange = async (event, api) => {
var adjusted_scopes = event.request.body.custom_scope
api.accessToken.setCustomClaim("https://adjusted-claims-for-my-backend-app", adjusted_scopes);
};

```

The original “scope” claim and “permissions” claim will remain unchanged, only the custom claim ships this contextual information.

Would this be something helpful for your use-case?

---

<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 30, 2024, 10:13am UTC](https://community.auth0.com/t/migrating-m2m-hook-with-custom-response-to-actions/124829/4 "2024-01-30T10:13:29Z")

</div>

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