# Enforce limits of M2M tokens on applications

**URL:** <https://community.auth0.com/t/enforce-limits-of-m2m-tokens-on-applications/136714>\
**Category:** Get Help\
**Tags:** apis, application\
**Created:** [June 20, 2024, 9:55am UTC](https://community.auth0.com/t/enforce-limits-of-m2m-tokens-on-applications/136714 "2024-06-20T09:55:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![timonbimon](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/timonbimon/32/41871_2.png) [@timonbimon](https://community.auth0.com/u/timonbimon)\
**Post date:** [June 20, 2024, 9:55am UTC](https://community.auth0.com/t/enforce-limits-of-m2m-tokens-on-applications/136714/1 "2024-06-20T09:55:25Z")

</div>

Hi there, one of our customers just used up around 70% of our M2M tokens within one hour (they had a script that looped and requested tokens endlessly). How can we restrict this to not happen again in the future (so as not to affect our other customers or force us to upgrade to higher limit just because of one customer’s mistake)?

I saw [this post](https://community.auth0.com/t/limit-the-number-of-m2m-token-exchanges-per-application/104501) talking about shipping such a feature but I could not find anything

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [June 20, 2024, 5:52pm UTC](https://community.auth0.com/t/enforce-limits-of-m2m-tokens-on-applications/136714/3 "2024-06-20T17:52:04Z")

</div>

Hi @timonbimon,

Welcome to the Auth0 Community!

You can use an M2M Action to enforce your own internal limits for M2M token authentication.

Additionally, you can cache the Management API tokens in the Action since these tokens do not expire immediately. This will help avoid going over the quota for your M2M token authentication.

For more details, see [this post on caching Management API access tokens in a login action](https://community.auth0.com/t/caching-management-api-access-tokens-in-login-action/95855).

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![timonbimon](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/timonbimon/32/41871_2.png) [@timonbimon](https://community.auth0.com/u/timonbimon)\
**Post date:** [June 20, 2024, 6:03pm UTC](https://community.auth0.com/t/enforce-limits-of-m2m-tokens-on-applications/136714/4 "2024-06-20T18:03:08Z")

</div>

Hi Rueben,

It seems like I’d need to connect to some kind of external database (to keep track of how many M2M tokens have been used per customer) to enforce the internal limits within an action (sounds rather complicated 😬).

Would the same be true for caching or is there some in-built cache I could use to cache the token within the Action? (edit: just saw you linked a post about the caching let me read that first 🙈)

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![timonbimon](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/timonbimon/32/41871_2.png) [@timonbimon](https://community.auth0.com/u/timonbimon)\
**Post date:** [June 20, 2024, 6:08pm UTC](https://community.auth0.com/t/enforce-limits-of-m2m-tokens-on-applications/136714/5 "2024-06-20T18:08:12Z")

</div>

OK answering my own question: seems like the caching is in-built =\> yay! Could you outline in a little more detail how I could use this cache feature to avoid that a call to the OAuth endpoint (the one below in our case) counts against our M2M token limit (by returning a cached token through an Action??).

```auto
curl --request POST \
  --url https://auth.luminovo.com/oauth/token \
  --header 'content-type: application/json' \
  --data '{"client_id":"some_client_id", "client_secret":"some_client_secret","audience":"https://luminovo.ai/api","grant_type":"client_credentials"}'

```

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [June 28, 2024, 11:47pm UTC](https://community.auth0.com/t/enforce-limits-of-m2m-tokens-on-applications/136714/6 "2024-06-28T23:47:37Z")

</div>

Hi @timonbimon,

You can use this cache feature in a [Post Login action script](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow).

Have you had a chance to review the knowledge solution below?  
[https://community.auth0.com/t/caching-management-api-access-tokens-in-login-action/95855](https://community.auth0.com/t/caching-management-api-access-tokens-in-login-action/95855)

Let me know what steps in the knowledge solution you are having issues with.

Thanks,  
Rueben

---

<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 12, 2024, 11:48pm UTC](https://community.auth0.com/t/enforce-limits-of-m2m-tokens-on-applications/136714/7 "2024-07-12T23:48:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david.lozano](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david.lozano/32/61143_2.png) [@david.lozano](https://community.auth0.com/u/david.lozano)\
**Post date:** [June 3, 2025, 5:52pm UTC](https://community.auth0.com/t/enforce-limits-of-m2m-tokens-on-applications/136714/8 "2025-06-03T17:52:17Z")

</div>

In response to the initial request in this thread, we’ve now released this as a feature. For details, search **“Fine-Grained Machine-to-Machine Token Quotas”** in our [changelog](https://auth0.com/changelog).

We also plan to extend availability to B2C/B2B Essentials and Professional plans later this year.

---

<div class="post-metadata">

**Author:** ![Tiffani](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tiffani/32/75235_2.png) [@Tiffani](https://community.auth0.com/u/Tiffani)\
**Post date:** [July 29, 2026, 4:48pm UTC](https://community.auth0.com/t/enforce-limits-of-m2m-tokens-on-applications/136714/9 "2026-07-29T16:48:13Z")

</div>


