我使用 .NET 4.5 创建了一个新的 ASP.NET MVC 应用程序。我已成功设置 STS 身份验证。身份验证流程工作正常,我能够在 Thread.CurrentPrincipal 上获取包含所需声明的 ClaimsIdentity。
现在我需要引导 token 来保护对我的服务层的调用。我已将 IdentityConfiguration 元素上的 saveBootstrapContext 设置为 true。
<system.identityModel>
<identityConfiguration saveBootstrapContext="true">
但是,ClaimsIdentity 上的 BootstrapContext 属性始终为 null。
var identity = Thread.CurrentPrincipal.Identity as ClaimsIdentity;
var context = identity.BootstrapContext; // context is always null
我在这里遗漏了什么吗?这本来应该很简单:(
最佳答案
通过这些解决了它:
<system.identityModel>
<identityConfiguration saveBootstrapContext="true" />
</system.identityModel>
还需要设置TokenValidationParameters.SaveSigninToken
,与JwtBearerOptions.SaveTokens不同:
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions {
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new TokenValidationParameters {
SaveSigninToken = true,
ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
}
}
);
关于asp.net-mvc - ClaimsIdentity 上的 BootstrapContext 为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14083885/