# Acquiring access token in rules or hooks extensibility points

**URL:** <https://community.auth0.com/t/acquiring-access-token-in-rules-or-hooks-extensibility-points/53964>\
**Category:** Get Help\
**Tags:** jwt, api, auth0\
**Created:** [November 27, 2020, 3:48pm UTC](https://community.auth0.com/t/acquiring-access-token-in-rules-or-hooks-extensibility-points/53964 "2020-11-27T15:48:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petko-Gotsov](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/petko-gotsov/32/25886_2.png) [@Petko-Gotsov](https://community.auth0.com/u/Petko-Gotsov)\
**Post date:** [November 27, 2020, 3:48pm UTC](https://community.auth0.com/t/acquiring-access-token-in-rules-or-hooks-extensibility-points/53964/1 "2020-11-27T15:48:42Z")

</div>

Greetings,

The case is that I want to enrich an access token with custom claims, pulled out of an Auth0 protected API(M2M app authorized for same Auth0 tenant). The way I initially went about this was to create a client credentials exchange hook, hoping to catch the access\_token in the context parameter of the hook function, and use it to query the external API and add the claim. This didn’t work though, as the context does not contain the access\_token. I found several topics on implementing the same behavior using rules, but no solution discoverable yet. I went through the documentation of the rules, and found several suggestions which do not fit my need. Those include making a connection to the database in the rule itself and querying it for the claim. The other one suggested authenticating with the external API using a secret string, stored in configuration. Both of these approaches seem unreliable to me. One of the [topics](https://community.auth0.com/t/using-an-access-token-in-a-rule/31427) mentioned using ‘node request example you can copy into the rule’, for which I could not find more info at this point.

Does anyone have any idea on best practices how to solve this?

---

<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:** [November 27, 2020, 7:24pm UTC](https://community.auth0.com/t/acquiring-access-token-in-rules-or-hooks-extensibility-points/53964/2 "2020-11-27T19:24:52Z")

</div>

Hi @Petko-Gotsov

You can use the webtask storage API to cache the tokens: [https://webtask.io/docs/storage](https://webtask.io/docs/storage)

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:** [November 30, 2020, 7:15am UTC](https://community.auth0.com/t/acquiring-access-token-in-rules-or-hooks-extensibility-points/53964/3 "2020-11-30T07:15:34Z")

</div>

Hey there!

Wanted to add a bit to that. As far as I remember unfortunately [webtask.io](http://webtask.io) platform is not accepting new signups for a while now so not sure if you will be able to use that.

---

<div class="post-metadata">

**Author:** ![Petko-Gotsov](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/petko-gotsov/32/25886_2.png) [@Petko-Gotsov](https://community.auth0.com/u/Petko-Gotsov)\
**Post date:** [November 30, 2020, 4:19pm UTC](https://community.auth0.com/t/acquiring-access-token-in-rules-or-hooks-extensibility-points/53964/4 "2020-11-30T16:19:38Z")

</div>

I found a solution, which is to call the credentials exchange oauth/token endpoint inside of the extensibility point hook, passing in a bool value so as to avoid endless loop. This way I can get the access\_token and query the API later on in the hook.

---

<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:** [December 1, 2020, 1:35pm UTC](https://community.auth0.com/t/acquiring-access-token-in-rules-or-hooks-extensibility-points/53964/5 "2020-12-01T13:35:23Z")

</div>

Perfect! Glad you have figured it out!

---

<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:** [December 8, 2020, 9:45am UTC](https://community.auth0.com/t/acquiring-access-token-in-rules-or-hooks-extensibility-points/53964/6 "2020-12-08T09:45:53Z")

</div>


