Rotem Slootzky
Rotem Slootzky

Reputation: 738

authentication token cache for azure function

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

Answers (1)

Paul Batum
Paul Batum

Reputation: 8415

Here a few options, in increasing order of effort

  1. 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.

  2. Make use of the temporary filesystem storage provided to functions. You can read/write files on %TEMP%.

  3. 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

Related Questions