# Oauth/token request payload custom key/values

**URL:** <https://community.auth0.com/t/oauth-token-request-payload-custom-key-values/122098>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [December 1, 2023, 2:24am UTC](https://community.auth0.com/t/oauth-token-request-payload-custom-key-values/122098 "2023-12-01T02:24:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian.flannery](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brian.flannery/32/49195_2.png) [@brian.flannery](https://community.auth0.com/u/brian.flannery)\
**Post date:** [December 1, 2023, 2:24am UTC](https://community.auth0.com/t/oauth-token-request-payload-custom-key-values/122098/1 "2023-12-01T02:24:13Z")

</div>

I have an m2m application and am trying to get a new oauth token using the POST ‘oauth/token’ endpoint.

Looking at the [Authentication API - Get Token](https://auth0.com/docs/api/authentication#get-token) docs, the request parameters show the following.

 ![Screenshot 2023-11-30 at 8.07.09 PM](https://global.discourse-cdn.com/auth0/original/3X/e/4/e494608d290b39a3a528f156299d136931df0424.png)

When testing this endpoint, I am able to send additional custom key/value pairs in the request body. Below is a sample request.

```auto
    response = httpx.post(
        f"https://{CONFIG.AUTH0_DOMAIN}/oauth/token",
        json={
            "grant_type": "client_credentials",
            "client_id": CONFIG.client_id,
            "client_secret": CONFIG.client_secret,
            "audience": CONFIG.API_AUDIENCE,
            "test_metadata": "test-metadata" // custom key/value pair
        },
    )

```

I’m wondering if including additional custom data is allowed and just not documented or if this is potentially a bug and should be avoided?

---

<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:** [December 1, 2023, 8:33am UTC](https://community.auth0.com/t/oauth-token-request-payload-custom-key-values/122098/2 "2023-12-01T08:33:56Z")

</div>

Hi @brian.flannery , welcome to Auth0!

In this case the additional parameter is ignored by the server.  
For example, sending both:  
1.

```auto
url --request POST \
  --url https://{auth0_domain}/oauth/token \
  --header 'content-type: application/json' \
  --data '{"client_id":"xxx","client_secret":"xxx","audience":"xxx/api/v2/","grant_type":"client_credentials"}'

```

1. 

```auto
url --request POST \
  --url https://{auth0_domain}/oauth/token \
  --header 'content-type: application/json' \
  --data '{"client_id":"xxx","client_secret":"xxx","audience":"xxx/api/v2/","grant_type":"client_credentials", "random_metadata":"random_value"}'

```

results in receiving a bearer token with scopes and expiry time as set in the Auth0 dashboard.

Is this also a behaviour that you can observe? Please let us know any questions.

---

<div class="post-metadata">

**Author:** ![brian.flannery](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/brian.flannery/32/49195_2.png) [@brian.flannery](https://community.auth0.com/u/brian.flannery)\
**Post date:** [December 1, 2023, 3:55pm UTC](https://community.auth0.com/t/oauth-token-request-payload-custom-key-values/122098/3 "2023-12-01T15:55:45Z")

</div>

I do see that the server ignores the additional custom field by default, however I don’t expect this out of box and am trying to use an action to manually set this field.

**Use case** : I want to add the additional metadata to the access token via setting custom claims.  
Below is a breakdown on my workflow

1. Send HTTP request to `oauth/token` to get an access token. Here is my sample request

```auto
 response = httpx.post(
        f"https://{CONFIG.AUTH0_DOMAIN}/oauth/token",
        json={
            "grant_type": "client_credentials",
            "client_id": CONFIG.client_id,
            "client_secret": CONFIG.client_secret,
            "audience": CONFIG.API_AUDIENCE,
            "test_metadata": "test-metadata" // custom key/value pair
        },
    )

```

1. Add a Machine-to-Machine action to intercept the Token Request ↔ Token Issued

 ![Screenshot 2023-12-01 at 9.34.29 AM](https://global.discourse-cdn.com/auth0/original/3X/0/8/08c7020807e2d52c1c9ad4ea41184f2fda5e0d18.png)

1. Get the `test_metadata` data field from the `event.request.body` and set `api.accessToken.setCustomClaim` equal to the field value

 ![Screenshot 2023-12-01 at 9.27.06 AM](https://global.discourse-cdn.com/auth0/original/3X/0/4/046deaf293412cd6cd8fc8f52f7ebb9c6391540a.png)

1. When my server receives and decodes this token, I’m able to grab the custom claim data from the payload

 ![Screenshot 2023-12-01 at 9.45.43 AM](https://global.discourse-cdn.com/auth0/original/3X/7/e/7e4228fa8aac24852a293a426feff48ac475adf9.png)

Testing all this locally I am able to get the custom field on to my access token as I want.

What I want to confirm though is that being able to send the custom field via the `/oauth/token` and grabbing it from the action event, is a valid approach and not just a loophole in the endpoint ↔ event action.

---

<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:** [December 5, 2023, 7:06am UTC](https://community.auth0.com/t/oauth-token-request-payload-custom-key-values/122098/5 "2023-12-05T07:06:12Z")

</div>

Hi @brian.flannery ,  
Thanks for your patience.

> [@brian.flannery](#):
>
> What I want to confirm though is that being able to send the custom field via the `/oauth/token` and grabbing it from the action event, is a valid approach and not just a loophole in the endpoint ↔ event action.

It is a valid approach, feel free to build on that.

> **[Actions Triggers: credentials-exchange - Event Object](https://auth0.com/docs/customize/actions/flows-and-triggers/machine-to-machine-flow/event-object)**
>
> Learn about the credentials-exchange Action trigger's event object, which provides contextual information about the request for a client credentials exchange.

---

<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 19, 2023, 7:06am UTC](https://community.auth0.com/t/oauth-token-request-payload-custom-key-values/122098/6 "2023-12-19T07:06:18Z")

</div>

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