2017-03-21 27 views
1

MVCを使用してSSOを実装しようとしています。
以下は、私の組織のADFSから生成されたサンプルSAMLの一部です。すべてのSAMLを取得できません:属性

<saml:AttributeStatement> 
    <saml:Subject> 
     <saml:SubjectConfirmation> 
      <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod> 
     </saml:SubjectConfirmation> 
    </saml:Subject> 
    <saml:Attribute AttributeName="upn" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims"> 
     <saml:AttributeValue>[email protected]</saml:AttributeValue> 
    </saml:Attribute> 
    <saml:Attribute AttributeName="emailaddress" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims"> 
     <saml:AttributeValue>[email protected]</saml:AttributeValue> 
    </saml:Attribute> 
    <saml:Attribute AttributeName="name" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims"> 
     <saml:AttributeValue>Sanketh K Jain</saml:AttributeValue> 
    </saml:Attribute> 
</saml:AttributeStatement> 

これは私が3つの属性を取得しようとしています方法です:

コントローラ

ViewBag.User = Thread.CurrentPrincipal.Identity as Microsoft.IdentityModel.Claims.ClaimsIdentity; 

ビュー

@{ 
    Microsoft.IdentityModel.Claims.ClaimsIdentity user = ViewBag.User; 
    <span>@user.Name</span><br /> 
    foreach(var c in user.Claims) 
    { 
     <span>@c.ClaimType --- </span> 
     <span>@c.Value</span> 
     <br /> 
    } 
} 

あなたが尋ねる前に、私はないですOWINのようなミドルウェアを使用しています。 Web.configファイルの変更点

しかし、このアプローチでは、私の出力は、私だけがこのようなUPNとemailaddressのようなその他の請求は、特許請求の範囲によってアクセスされていない理由を知っていただきたいと思います私に

Sanketh K Jain 
http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name --- Sanketh K Jain 

を与えます。私はADFSの実装に何も間違いがないことはかなり確信していますが、そのような場合には、より良いアプローチについてアドバイスをしてください。

答えて

1

あなたのコントローラでは、Microsoft.IdentityModel.Claimsを使用し、ビューでlooptのクレームを使用する必要があります。

電子メールアドレスの例は、次の項目で確認できます。c.ClaimType == ClaimTypes.Email。

+0

Microsoft.IdentityModel.Claimsは名前空間です。私はそれをループすることはできません。 –

+0

コレクションはどうなりますか?すべての属性が存在するかどうかチェックしましたか? – papanoel49

+0

Microsoft.IdentityModel.Claims.ClaimsCollectionsについて言えば、それはnullです。 すべての属性はどこにありますか? –

関連する問題