Reputation: 738
We use an Identity server to issue tokens for 3rd party service we use.
Each token have TTL of 1 hour. Wanted to know what is the best practice for caching this token when consuming it from an azure function. I know that function should be stateless but it's makes no sense to ask for a new token in every function run. Thanks.
Upvotes: 9
Views: 4145
Reputation: 8415
Here a few options, in increasing order of effort
Use a static member to store the token in memory, and lazily do the authentication process when necessary. There are absolutely no guarantees about how often this will save you the authentication step - it will vary wildly depending on how often your function is running, on how many different machines, etc.
Make use of the temporary filesystem storage provided to functions. You can read/write files on %TEMP%.
Use a persistent external store such as a database, redis cache, etc.
Please note that I'm listing these options without considering whether you have additional security requirements regarding the persistence of the token.
Upvotes: 9