我正在使用httpclient从ASP.NET MVC中消费JWT令牌
代币应该在哪里保存在服务器端会话上或作为客户端浏览器存储在cookie中?我正在使用httpclient
消耗而不是AJAX。
Where should the token be saved on the server side session or stored in the cookie as the client browser? I am using HttpClient
to consume and not ajax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您与令牌服务器协商的JWT令牌是特定于客户端的(例如:使用客户端凭据流的OIDC客户端的访问令牌),您可以安全地将其存储在缓存中(可以是服务器端存储器缓存或任何类型分布式缓存)。无需将其保存在用户的身份验证cookie中。
如果JWT令牌是用户特定的(例如:用户在交互式登录流程中获得的JWT访问令牌,例如MVC应用程序的OIDC Hybrid Flow),那么最好的方法就是将其保存为用户身份验证的一部分。曲奇饼。这比将其保存在服务器端会话中要好得多,因为您避免使用服务器端的亲和力,并且您的系统将无状态并能够更好地缩放。
因此,总结:
If the JWT token that you negotiate with the token server is client specific (e.g.: an access token for an OIDC client using the client credentials flow) you can safely store it in a cache (it can be a server side memory cache or any sort of distributed cache). There is no need to save it in the authentication cookie of the user.
If the JWT token is, instead, user specific (e.g.: a JWT access token that a user get during an interactive login flow, such as the OIDC hybrid flow for an MVC application) the best approach is saving it as part of the user authentication cookie. This is much better than saving it inside the server side session, because you avoid server side affinity and your system will be stateless and capable of scalign much better.
So, to summarize: