用于 Azure 功能的身份验证令牌缓存 [英] authentication token cache for azure function

查看:17
本文介绍了用于 Azure 功能的身份验证令牌缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用身份服务器为我们使用的第 3 方服务颁发令牌.

We use an Identity server to issue tokens for 3rd party service we use.

每个令牌的 TTL 为 1 小时.想知道从 azure 函数中使用此令牌时缓存此令牌的最佳做法是什么.我知道该函数应该是无状态的,但是在每个函数运行时都要求一个新令牌是没有意义的.谢谢.

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.

推荐答案

这里有几个选项,按工作量递增的顺序排列

Here a few options, in increasing order of effort

  1. 使用静态成员将令牌存储在内存中,并在必要时懒惰地进行身份验证过程.绝对不能保证这会多久为您节省身份验证步骤 - 它会根据您的功能运行频率、不同机器的数量等而有很大差异.

  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.

利用为函数提供的临时文件系统存储.您可以在 %TEMP% 上读取/写入文件.

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

使用持久化的外部存储,例如数据库、redis 缓存等

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.

这篇关于用于 Azure 功能的身份验证令牌缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆