Get Adfs Decrypted SAML Value in C#


     In This Section, We Can See about How to Get Data From ADFS SAML Decrypted Response. Next Session We See about How to Get SAML Encrypted Response From ADFS. Below I Show the Decrypted Response.
       Last Part We See About Decrypted the SAML Response. In this Section How to Read ADFS Decrypted Response to Data Information or Decode the ADFS Response.

SAML Decrypted Response:


<Subject
xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
<NameID>test1011</NameID>
<SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
    <SubjectConfirmationData NotOnOrAfter="2018-02-22T04:29:26.735Z" Recipient="https://example.com/adfsauthlogin/login" />
</SubjectConfirmation>
</Subject>
<Conditions NotBefore="2018-02-22T04:24:26.673Z" NotOnOrAfter="2018-02-22T05:24:26.673Z"
xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
    <AudienceRestriction>
    <Audience>https://example.com/adfs/ls/</Audience>
</AudienceRestriction>
</Conditions>
<AttributeStatement
xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
<Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname">
    <AttributeValue>User</AttributeValue>
</Attribute>
<Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress">
    <AttributeValue>test.user@test.com</AttributeValue>
</Attribute>
<Attribute Name="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname">
    <AttributeValue>Test</AttributeValue>
</Attribute>
</AttributeStatement>


C# Code:
            string userName = "";
            string givenname = "";
            string surname = "";
            string emailaddress = "";

            if (samlAssertion.Subject.NameID != null)
            {
                userName = samlAssertion.Subject.NameID.NameIdentifier;
            }

            if (samlAssertion.GetAttributeValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress") != null)
            {
                emailaddress = samlAssertion.GetAttributeValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress");
            }

            if (samlAssertion.GetAttributeValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname") != null)
            {
                givenname = samlAssertion.GetAttributeValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname");
            }

            if (samlAssertion.GetAttributeValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname") != null)
            {
                surname surname = samlAssertion.GetAttributeValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname");
            }






Comments

Popular posts from this blog

Insecure cookie setting: missing Secure flag

Maximum Stored Procedure Function Trigger or View Nesting Level Exceeded (limit 32) in SQL Server

Display Line Chart Using Chart.js MVC C#