我正在使用httpclient从ASP.NET MVC中消费JWT令牌

发布于 2025-02-04 19:40:33 字数 84 浏览 2 评论 0原文

代币应该在哪里保存在服务器端会话上或作为客户端浏览器存储在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯角 2025-02-11 19:40:33

如果您与令牌服务器协商的JWT令牌是特定于客户端的(例如:使用客户端凭据流的OIDC客户端的访问令牌),您可以安全地将其存储在缓存中(可以是服务器端存储器缓存或任何类型分布式缓存)。无需将其保存在用户的身份验证cookie中。

如果JWT令牌是用户特定的(例如:用户在交互式登录流程中获得的JWT访问令牌,例如MVC应用程序的OIDC Hybrid Flow),那么最好的方法就是将其保存为用户身份验证的一部分。曲奇饼。这比将其保存在服务器端会话中要好得多,因为您避免使用服务器端的亲和力,并且您的系统将无状态并能够更好地缩放。

因此,总结:

  • 在服务器端缓存中保存客户端特定的访问令牌(例如:内存缓存或服务器应用程序实例之间共享的分布式缓存)
  • 保存在用户身份验证cookie中的用户特定访问令牌。避免使用任何服务器端会话状态,以便您获得一项无端服务,并避免使用登录用户的服务器亲和力

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:

  • save client specific access tokens in a server side cache (e.g: memory cache or a distributed cache shared between instances of your server application)
  • save user specific access tokens in the user authentication cookie. Avoid any server side session state, so that you get a steteless service and you avoid server affinity bound for the logged in user
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文