# Cache a machine to machine access token used in rules

**URL:** <https://community.auth0.com/t/cache-a-machine-to-machine-access-token-used-in-rules/70707>\
**Category:** Get Help\
**Created:** [October 3, 2021, 3:44pm UTC](https://community.auth0.com/t/cache-a-machine-to-machine-access-token-used-in-rules/70707 "2021-10-03T15:44:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vigi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vigi/32/12799_2.png) [@vigi](https://community.auth0.com/u/vigi)\
**Post date:** [October 3, 2021, 3:44pm UTC](https://community.auth0.com/t/cache-a-machine-to-machine-access-token-used-in-rules/70707/1 "2021-10-03T15:44:56Z")

</div>

I have seen some posts here regarding using global to cache a machine to machine access token (Management API) for use in rules. It seems this works between the various rules that are executed upon authentication.

Any suggestions on how to cache a token across all authentications. It seems that acquiring an access token on each authentication is excessive if a token lasts a day or so and can be shared.

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [October 4, 2021, 2:29pm UTC](https://community.auth0.com/t/cache-a-machine-to-machine-access-token-used-in-rules/70707/2 "2021-10-04T14:29:09Z")

</div>

Hi @vigi

The trick is to use the rules’ config variables as the cache. A config variable can be updated with the Auth0 Management API:

managementClient.setRulesConfig

There’s some code to wrap around that, of course, but that is the heart of the idea.

John

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 8, 2024, 8:50am UTC](https://community.auth0.com/t/cache-a-machine-to-machine-access-token-used-in-rules/70707/3 "2024-01-08T08:50:03Z")

</div>

Hey there!

As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon I’m excited to let you know about our next [Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043) on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

[Learn more here!](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043)

---

<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 22, 2024, 8:50am UTC](https://community.auth0.com/t/cache-a-machine-to-machine-access-token-used-in-rules/70707/4 "2024-01-22T08:50:47Z")

</div>

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