2013-11-20 116 views
3

我已经使用微软的“本地”组织帐户认证机制创建了一个ASP.Net MVC 5网站。这最终配置为指向我公司的ADFS基础架构。我找回所有配置的声明。但是,在运行时,ClaimsIdentity.Name是空的。这是因为ClaimsIdentity.NameClaimType,默认情况下,似乎是:如何在ASP.Net MVC 5网站中设置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元素的添加元素中:

<system.identityModel> 
    <identityConfiguration> 
    <securityTokenHandlers> 
     <add> 
     <samlSecurityTokenRequirement> 
      <nameClaimType value=xs:string> 
      </nameClaimType> 
     </samlSecurityTokenRequirement> 
     </add> 
    </securityTokenHandlers> 
    </identityConfiguration> 
</system.identityModel> 

在我的ASP.Net MVC 5 web.config中,看起来适用的唯一的事情,并通过intellisense检查结果看起来像这样:

<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 

我应该我的web.config看起来喜欢我的现有要求到ClaimsIdentity.Name字段映射?

回答

2

我发现,使用以下securityTokenHandlers节让我的地方,我需要的是基于SAML 2.0的有效载荷从我的ADFS系统:

<securityTokenHandlers> 
    <add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
    <remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
    <remove type="System.IdentityModel.Tokens.Saml2SecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
    <add type="System.IdentityModel.Tokens.Saml2SecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > 
    <samlSecurityTokenRequirement> 
     <nameClaimType value="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname"/> 
    </samlSecurityTokenRequirement> 
    </add> 
</securityTokenHandlers> 

我不能完全肯定如何索赔被由于没有配置Saml令牌处理程序,因此使用默认的web.config。也许在源代码中的某些默认行为...

相关问题