首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ClaimsIdentity上的BootstrapContext为空

ClaimsIdentity上的BootstrapContext为空
EN

Stack Overflow用户
提问于 2012-12-30 00:57:21
回答 4查看 9.1K关注 0票数 8

我已经用.NET 4.5创建了一个新的ASP.NET MVC应用程序。我已成功使用STS设置身份验证。身份验证流工作正常,我能够在Thread.CurrentPrincipal上获得包含所需声明的ClaimsIdentity。

现在,我需要bootstrap令牌来保护对服务层的调用。我已经在identityConfiguration元素上将saveBootstrapContext设置为true。

代码语言:javascript
复制
<system.identityModel>
    <identityConfiguration saveBootstrapContext="true">

但是,ClaimsIdentity上的BootstrapContext属性始终为空。

代码语言:javascript
复制
var identity = Thread.CurrentPrincipal.Identity as ClaimsIdentity;
var context = identity.BootstrapContext; // context is always null

我是不是漏掉了什么?这本应简单明了:

EN

回答 4

Stack Overflow用户

发布于 2015-11-20 20:44:53

通过以下方式解决了这个问题:

代码语言:javascript
复制
<system.identityModel>
    <identityConfiguration saveBootstrapContext="true" />
</system.identityModel>

还需要设置与JwtBearerOptions.SaveTokens不同的TokenValidationParameters.SaveSigninToken

代码语言:javascript
复制
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
    new WindowsAzureActiveDirectoryBearerAuthenticationOptions {
        Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
        TokenValidationParameters = new TokenValidationParameters {
            SaveSigninToken = true,               
            ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
        }
    }
);
票数 8
EN

Stack Overflow用户

发布于 2013-01-23 02:43:32

我在IIS Express中托管时遇到了这个问题。事实证明,问题出在我的浏览器上--我没有关闭所有的浏览器窗口或清除cookie,所以即使服务器已经重新启动(浏览器仍在发送现有的FedAuth cookie),也不会使用新的设置重新创建cookie。

一旦我通过关闭所有浏览器窗口,重新启动浏览器并再次执行我的请求来强制重新身份验证,BootstrapContext就出现了。

票数 3
EN

Stack Overflow用户

发布于 2014-08-12 12:39:48

如果您使用消息处理程序手动验证令牌,并使用JwtSecurityTokenHandler提取声明主体并将其附加到当前线程,如Using the JWT handler for Implementing “Poor Man”’s Delegation/ActAs中所述,当您使用JwtSecurityTokenHandler.ValidateToken()验证令牌时,TokenValidationParameters上的设置之一是SaveBootstrapContext,设置为true即可完成此操作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14083885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档