# M2M Tokens with org\_id

**URL:** <https://community.auth0.com/t/m2m-tokens-with-org-id/137876>\
**Category:** Get Help\
**Tags:** customer-feedback\
**Created:** [July 1, 2024, 5:43pm UTC](https://community.auth0.com/t/m2m-tokens-with-org-id/137876 "2024-07-01T17:43:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PatrickHeneise](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/patrickheneise/32/39821_2.png) [@PatrickHeneise](https://community.auth0.com/u/PatrickHeneise)\
**Post date:** [July 1, 2024, 5:43pm UTC](https://community.auth0.com/t/m2m-tokens-with-org-id/137876/1 "2024-07-01T17:43:50Z")

</div>

I just read the “Building B2B SaaS Products” post from @shreya.gupta and have a question / issue that has been bugging my team and me for over a year now:

I want to test my Organization-enabled (exclusive for organizations, no `org_id` → no access) API. This is impossible since:

" \* Organizations-enabled applications are not compatible with the following grants and protocols: Resource Owner Password, Client Credentials, Device Authorization Flow, WS-Fed (Auth0 as IdP)." - [Understand How Auth0 Organizations Work](https://auth0.com/docs/manage-users/organizations/organizations-overview)

I could solve the permission/role tests with M2M tokens, but M2M tokens do not have an `org_id`, which means access to the API is prohibited.

How do I solve this?

---

<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:** [July 2, 2024, 9:24pm UTC](https://community.auth0.com/t/m2m-tokens-with-org-id/137876/2 "2024-07-02T21:24:48Z")

</div>

Hey there @PatrickHeneise!

> [@PatrickHeneise](#):
>
> I could solve the permission/role tests with M2M tokens, but M2M tokens do not have an `org_id`, which means access to the API is prohibited.

Thinking out loud here - Have you considered just adding the `org_id` as a custom claim to the m2m token in an [action](https://auth0.com/docs/customize/actions/flows-and-triggers/machine-to-machine-flow)? You won’t be able to use `org_id` as it’s [restricted](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#general-restrictions), but you could use something like `test_org_id`. This would require your API checking for the custom claim as opposed to `org_id`:

```auto
exports.onExecuteCredentialsExchange = async (event, api) => {
  if (event.client.client_id === 'YOUR_M2M_CLIENT_ID') {
    api.accessToken.setCustomClaim('test_org_id', 'YOUR_ORG_ID');
  }
};

```

---

<div class="post-metadata">

**Author:** ![PatrickHeneise](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/patrickheneise/32/39821_2.png) [@PatrickHeneise](https://community.auth0.com/u/PatrickHeneise)\
**Post date:** [July 10, 2024, 5:19pm UTC](https://community.auth0.com/t/m2m-tokens-with-org-id/137876/4 "2024-07-10T17:19:54Z")

</div>

Thanks, but that would also mean special logic in my app to handle this case for testing, which is not ideal. I’d prefer to have a proper solution from auth0 for this.

---

<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:** [July 10, 2024, 11:03pm UTC](https://community.auth0.com/t/m2m-tokens-with-org-id/137876/5 "2024-07-10T23:03:25Z")

</div>

No worries, happy to help where I can 🙂 Unfortunately, as M2M tokens don’t support an organization I can’t see that being an option for strictly testing, but feel free to create a #Feedback request.

The only other option I can really think of for testing given the `org_id` requirement is creating a test user(s) of organizations - Auth0 unfortunately doesn’t offer any sort of user impersonation so this may be your best bet. The [auth0-cli](https://github.com/auth0/auth0-cli) provides a [test token](https://auth0.github.io/auth0-cli/auth0_test_token.html) command which could be useful in generating an access token for test users.

---

<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:** [July 24, 2024, 11:03pm UTC](https://community.auth0.com/t/m2m-tokens-with-org-id/137876/6 "2024-07-24T23:03:27Z")

</div>

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