在 Forms Authentication MVC 应用程序中管理 ClaimsPrincipal.Current

Managing ClaimsPrincipal.Current in Forms Authentication MVC app

我们使用优秀的 Thinktecture IdentityServer v2 来管理我们的身份验证。这适用于底层 SqlMembershipProvider 架构。我想使用 Identity Server 在令牌中返回的信息(声明)来管理 ASP.NET MVC4 Web 应用程序连接。现在,当 OAuth2Client.RequestResourceOwnerPasswordAsync() returns 一个 AccessToken 时,我只是用用户名设置授权 cookie。我什至没有验证它(这会设置 ClaimsPrincipal.Current),因为它的目的是在我稍后调用的另一个网站 API 上使用,所以它在这个网站 API 中被验证。

如果我验证令牌并将 ClaimsPrincipal.Current.Identity 设置为我得到的令牌,在每次调用时检索它的机制是什么?我是否必须缓存令牌并在每次请求时再次验证它才能获取它?

所有这一切的目的是在 wep 应用程序端获得我的声明,以便我可以基于它们应用授权过滤器。

Thinktecture 的 Brock Allen 向我推荐了他的 2 篇精彩帖子,解答了我所有的疑虑!

http://brockallen.com/2013/01/26/replacing-forms-authentication-with-wifs-session-authentication-module-sam-to-enable-claims-aware-identity/

http://brockallen.com/2013/10/24/a-primer-on-owin-cookie-authentication-middleware-for-the-asp-net-developer/