Unm*_*kar 8 asp.net-mvc claims-based-identity wif ws-federation .net-4.5
我用.NET 4.5创建了一个新的ASP.NET MVC应用程序.我已成功使用STS设置身份验证.身份验证流程正常,我可以在Thread.CurrentPrincipal上获取包含所需声明的ClaimsIdentity.
现在我需要引导令牌来保护对我的服务层的调用.我在identityConfiguration元素上将saveBootstrapContext设置为true.
<system.identityModel>
<identityConfiguration saveBootstrapContext="true">
Run Code Online (Sandbox Code Playgroud)
但是,ClaimsIdentity上的BootstrapContext属性始终为null.
var identity = Thread.CurrentPrincipal.Identity as ClaimsIdentity;
var context = identity.BootstrapContext; // context is always null
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?这被认为是直截了当的:(
- - - - - - 解决 - - - - - -
重新启动系统后,此问题已得到解决.请注意,在iisreset之后它没有解决.后来我更改了配置以使用Microsoft.IdentityModel而不是System.IdentityModel.我能够重现这种行为.再次重启后,我又能够再次获得引导令牌.其他人有同样的行为吗?
解决了这些:
<system.identityModel>
<identityConfiguration saveBootstrapContext="true" />
</system.identityModel>
Run Code Online (Sandbox Code Playgroud)
还需要设置TokenValidationParameters.SaveSigninToken,这与JwtBearerOptions.SaveTokens不同:
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions {
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new TokenValidationParameters {
SaveSigninToken = true,
ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
}
}
);
Run Code Online (Sandbox Code Playgroud)
我在 IIS Express 中托管时遇到了这个问题。事实证明,问题出在我的浏览器上 - 我没有关闭所有浏览器窗口或清除 cookie,因此即使服务器已重新启动(现有的 FedAuth cookie 仍在使用中),也不会使用新设置重新创建 SessionSecurityToken。从浏览器发送)。
当我通过关闭所有浏览器窗口、重新启动浏览器并再次执行我的请求来强制重新进行身份验证时,BootstrapContext 就出现了。
| 归档时间: |
|
| 查看次数: |
7567 次 |
| 最近记录: |