2013-11-20 157 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。也許在源代碼中的某些默認行爲...

相關問題