# Machine to machine with user context?

**URL:** <https://community.auth0.com/t/machine-to-machine-with-user-context/124034>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [January 3, 2024, 9:34am UTC](https://community.auth0.com/t/machine-to-machine-with-user-context/124034 "2024-01-03T09:34:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roman.r](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/roman.r/32/49631_2.png) [@roman.r](https://community.auth0.com/u/roman.r)\
**Post date:** [January 3, 2024, 9:34am UTC](https://community.auth0.com/t/machine-to-machine-with-user-context/124034/1 "2024-01-03T09:34:37Z")

</div>

Hello Community!

We have our Backend API that is protected by JWT access token issues by Auth0.  
We have an SPA that allows users to get access tokens by Auth0 with Google identity provider.

We would like to allow our users to be able to get access tokens for M2M communication in behalf of them. i.e. it’s like Client Credentials Flow but with the user’s context.  
Is there any way we can achieve 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 3, 2024, 3:08pm UTC](https://community.auth0.com/t/machine-to-machine-with-user-context/124034/3 "2024-01-03T15:08:02Z")

</div>

Hi @roman.r and welcome to Auth0!

Thanks for posting!

> [@roman.r](#):
>
> We would like to allow our users to be able to get access tokens for M2M communication in behalf of them. i.e. it’s like Client Credentials Flow but with the user’s context.

To make an access (bearer) token distinguishable (containing some user specific data) you can try  
to implement Actions script.

Specifically: the Machine to Machine Flow and the `event.request.body` method (to extract a custom “key”: “value” params sent to the `POST https://domain.auth0.com/oauth/token` endpoint. This custom param would contain user specific data.  
Later, using the `api.accessToken.setCustomClaim(name, value)` within the same Action, you can add a custom claim to the access token containing this user-specific data sent within the request.

The doc on Machin to Machin Flow is here - [Actions Triggers: credentials-exchange - Event Object](https://auth0.com/docs/customize/actions/flows-and-triggers/machine-to-machine-flow/event-object).

Would it be something you’re looking for?

---

<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 17, 2024, 3:09pm UTC](https://community.auth0.com/t/machine-to-machine-with-user-context/124034/4 "2024-01-17T15:09:02Z")

</div>

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