我已经用.NET 4.5创建了一个新的ASP.NET MVC应用程序。我已成功使用STS设置身份验证。身份验证流工作正常,我能够在Thread.CurrentPrincipal上获得包含所需声明的ClaimsIdentity。
现在,我需要bootstrap令牌来保护对服务层的调用。我已经在identityConfiguration元素上将saveBootstrapContext设置为true。
<system.identityModel>
<identityConfiguration saveBootstrapContext="true">但是,ClaimsIdentity上的BootstrapContext属性始终为空。
var identity = Thread.CurrentPrincipal.Identity as ClaimsIdentity;
var context = identity.BootstrapContext; // context is always null我是不是漏掉了什么?这本应简单明了:
发布于 2015-11-20 20:44:53
通过以下方式解决了这个问题:
<system.identityModel>
<identityConfiguration saveBootstrapContext="true" />
</system.identityModel>还需要设置与JwtBearerOptions.SaveTokens不同的TokenValidationParameters.SaveSigninToken、
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions {
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new TokenValidationParameters {
SaveSigninToken = true,
ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
}
}
);发布于 2013-01-23 02:43:32
我在IIS Express中托管时遇到了这个问题。事实证明,问题出在我的浏览器上--我没有关闭所有的浏览器窗口或清除cookie,所以即使服务器已经重新启动(浏览器仍在发送现有的FedAuth cookie),也不会使用新的设置重新创建cookie。
一旦我通过关闭所有浏览器窗口,重新启动浏览器并再次执行我的请求来强制重新身份验证,BootstrapContext就出现了。
发布于 2014-08-12 12:39:48
如果您使用消息处理程序手动验证令牌,并使用JwtSecurityTokenHandler提取声明主体并将其附加到当前线程,如Using the JWT handler for Implementing “Poor Man”’s Delegation/ActAs中所述,当您使用JwtSecurityTokenHandler.ValidateToken()验证令牌时,TokenValidationParameters上的设置之一是SaveBootstrapContext,设置为true即可完成此操作。
https://stackoverflow.com/questions/14083885
复制相似问题