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.
The Azure App Service Local Cache feature provides a web role view of your content. This content is a write-but-discard cache of your storage content that is created asynchronously on-site startup. When the cache is ready, the site is switched to run against the cached content.
If any of the third-party scripts you include in your page is compromised, it can access all your users' tokens. To keep them secure, you should always store JWTs inside an httpOnly cookie. This is a special kind of cookie that's only sent in HTTP requests to the server.
Our CACHE Gold Token (CGT) transparently combines the unique qualities of gold with the benefits of a modern crypto asset. Fully backed, redeemable, regulated and with worldwide liquidity, one CGT represents one gram of pure gold.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With