Problem statement
I am working on finding a better solution to caching machine to machine tokens that we are using in the rules pipeline. We were using the global object, but because of the different containers and recycling of the object, we were still creating multiple tokens every ~3 minutes.
I had come across a solution in an Auth0 Community thread that is using the configuration variables to store the token:
This works for the most part and our m2m token creation went down, but we came across an issue of the configuration not being updated in later rules, it seems to be cached from the beginning of the container instance.
My question is, is there a way to refresh the configurations in the later rules so we can use the newly created token?
Solution
This may depend on how exactly you are using this, but one possibility is to simply set the new token one the global object - as all the rules in the same transaction will be executed in the same container and the global object will always be there.
For example, you can read and update the configuration variable, but also update the value in the global object. The top-most rule will read the configuration variables and update the global object. And all subsequent operations will be referring to this only. If a rule updates the config value, it will also be updating the global object as well, so there’s no need to ‘refresh’ the config.