My apologies if this information is present somewhere, but I’m trying to figure out how to cache a machine to machine bearer token in an Auth0 hook in a fashion that’s similar to this method that works for rules: How do I get an access token to call Management API v2 from a rule?
I tried searching the docs and the community, and I turned up this doc article:
However, this appears to be a different type of hook than the one I’m working with because the signature is very different. Regardless, I tried printing the value of context.global and running a test of my client credentials exchange hook and it appears to be undefined:
10:14:50 AM:
new webtask request 1563286490891.737686
10:14:50 AM:
Before Global
10:14:50 AM:
finished webtask request 1563286490891.737686 with HTTP 200 in 13ms
This print statement works in rules where I noticed there was a circular reference. I had a sneaking suspicion that the console in the hook editor was discarding the log statement due to the circular reference, so I checked to see if stringify would throw an error on it.
10:18:53 AM:
Code generated an uncaught exception: TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
at module.exports (/data/io/6cea6856-0cb1-4dbe-b36a-40b711e4a364/webtask.js:17:20)
at Authz.is_authorized.error (/data/sandbox/node_modules/auth0-ext-compilers/lib/compilers/client_credentials_exchange.js:27:16)
at Object.is_authorized (/data/sandbox/node_modules/auth0-ext-compilers/lib/authorization.js:13:81)
at clientCredentialsExchangeHandler (/data/sandbox/node_modules/auth0-ext-compilers/lib/compilers/client_credentials_exchange.js:9:18)
at parseBody (/data/sandbox/node_modules/auth0-ext-compilers/lib/adapter.js:90:20)
at finish (/data/sandbox/node_modules/auth0-ext-compilers/node_modules/wreck/lib/index.js:369:16)
at wrapped (/data/sandbox/node_modules/auth0-ext-compilers/node_modules/hoek/lib/index.js:879:20)
at module.exports.internals.Recorder.onReaderFinish (/data/sandbox/node_modules/auth0-ext-compilers/node_modules/wreck/lib/index.js:415:16)
at Object.onceWrapper (events.js:313:30)
That confirms that global exists and is set. Thanks for your assistance Nicolas!