How to Get ADFS SAML Response in C#

     ADFS  For Active Directory Federation Services which can Installed on IIS Server. We Will See About How To Configure ADFS in IIS SERVER. ADFS is One of The Single Sign-On Technology from Microsoft.
        After Configured Login Process Held on Central ADFS Server to Your Own Post Page. You Can Configure that Post Page which Control Method's Comes The ADFS Response.
        ADFS Response is Secured and Encrypted. Do Not Take Information Without Decrypt the Response. ADFS Response like Locked Home, If Need To open the Door We Need to use Key(Certificate) then Break the Latch(ADFS Response). In this Section How to Decrypt ADFS Response Process Explained Detaily. 

    


ADFS Response:


<samlp:Response Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified"
    Destination="https://example.com/adfsauthlogin/login"
    ID="_73cad836-4090-4812-9d2e-bfda9adc01f1" IssueInstant="2018-02-18T06:17:20.476Z" Version="2.0"
    xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
    <Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion">http://adfs.example.com/adfs/services/trust</Issuer>
    <samlp:Status><samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/></samlp:Status>
    <EncryptedAssertion xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
        <xenc:EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
            xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"><xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
            <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
                <e:EncryptedKey xmlns:e="http://www.w3.org/2001/04/xmlenc#">
                    <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/></e:EncryptionMethod>
                    <KeyInfo>
                        <ds:X509Data xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
                            <ds:X509IssuerSerial>
                                <ds:X509IssuerName>CN=Secure Certificate,
                                    OU=http://certs.com/repository/, O="y.com, Inc.", L=Scot, S=A, C=US</ds:X509IssuerName>
                                <ds:X509SerialNumber>684525798342703</ds:X509SerialNumber>
                            </ds:X509IssuerSerial>
                        </ds:X509Data>
                    </KeyInfo>
                    <e:CipherData>
                        <e:CipherValue>--Sample CipherValue--</e:CipherValue>
                    </e:CipherData>
                </e:EncryptedKey>
            </KeyInfo>
            <xenc:CipherData>
                <xenc:CipherValue>  -- Sample CipherValue-- </xenc:CipherValue>
            </xenc:CipherData>
        </xenc:EncryptedData>
    </EncryptedAssertion>
</samlp:Response>

Now We Can See about How to Get Saml Response in C#. You can Get the SamlResponse Request Method.

        [HttpPost]

        [AllowAnonymous]
        public ActionResult login()
        {

            string rawSamlData = Request["SAMLResponse"];
            SAMLAssertion samlAssertionNew = null;
            XmlElement samlAssertionXml = null;

            if (rawSamlData.Contains('%'))
            {
                rawSamlData = HttpUtility.UrlDecode(rawSamlData);
            }

            byte[] samlData = Convert.FromBase64String(rawSamlData);

            var samlAssertion = Encoding.UTF8.GetString(samlData);
     }

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#