Hello!
The goal:
My goal is to reduce usage of M2M tokens. We have some internal APIs that communicate using M2M tokens and we have problems with the monthly quota (it is exceeded every month now). My initial thought was that I have to take a look on client side of m2m token utilization (use until expires, cache etc) but I discovered that m2m tokens caching was introduced yeey! (See here)
That was the answer for me, just create new Action and we are good but seems like this is not the truth.
The problem:
According to the linked blogpost what should be available is caching m2m token to âavoid exceeding their quotas on machine-to-machine exchangesâ but it seems like it is not possible.
Every topic on this forum I saw was about caching Management API token, not regular M2M token generated by client credentials grant. Management API tokens are not included in quota (see here) so the only benefit is the performance.
I tried to do it by myself by checking API docs. By looking into m2m flow I assumed that what I need is:
- create an Action for
credentials-exchange
trigger. (M2M / Client-Credentials action,onExecuteCredentialsExchange
function) - check if there is a cached token for current client_id or is expired, if not then request a token and add to cache
- get token from cache and return it
To do it I should be able to somehow prevent default behavior of this flow (returning from function) or use available API to change the token the flow will return. Checked event object, API object and auth0 nodejs SDK docs and I donât see how this could be possible.
What worries me the most is this post and response. Looks like this is not possible which is opposite to the official blog post so Iâm super confused.
Please help with this and letâs answer the big question: is caching m2m token generated by /oauth/token
endpoint with client_credentials
grant type possible.