【发布时间】:2013-12-05 01:48:13
【问题描述】:
我使用 Microsoft 的“本地”组织帐户身份验证机制创建了一个 ASP.Net MVC 5 站点。这最终配置为指向我公司的 ADFS 基础架构。我正在取回所有已配置的声明。但是,在运行时,ClaimsIdentity.Name 是空白的。这是因为默认情况下,ClaimsIdentity.NameClaimType 似乎是:
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
但是,我希望将 ClaimsIdentity.Name 映射到:
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier
根据Microsoft Docs,在 web.config 中设置这个的地方是在 securityTokenHandlers 元素的 Add 元素中:
<system.identityModel>
<identityConfiguration>
<securityTokenHandlers>
<add>
<samlSecurityTokenRequirement>
<nameClaimType value=xs:string>
</nameClaimType>
</samlSecurityTokenRequirement>
</add>
</securityTokenHandlers>
</identityConfiguration>
</system.identityModel>
在我的 ASP.Net MVC 5 web.config 中,唯一看起来适用并通过智能感知检查的东西最终看起来像这样:
<system.identityModel>
<identityConfiguration>
<securityTokenHandlers>
<add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<samlSecurityTokenRequirement>
<nameClaimType value="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"/>
</samlSecurityTokenRequirement>
</add>
<remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</securityTokenHandlers>
</identityConfiguration>
</system.identityModel>
但是,这似乎没有效果。我的 MVC 应用程序仍然报告一个空白的 ClaimsIdentity.Name 字段,并且 ClaimsIdentity.NameClaimType 仍然是:
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
在将现有声明映射到 ClaimsIdentity.Name 字段时,我的 Web.Config 应该是什么样子?
【问题讨论】:
标签: asp.net authentication asp.net-mvc-5