Click here to Skip to main content
15,666,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am doing a POC in ASP.Net for IdP Initiated SSO.
I get logged in successfully with my AD credentials on ADFS login page.
But, on my assertion page, how can I get the SAML response and validate the the user?
I can see the response using developer tool but how can I get it using c#?

What I have tried:

I tried printing the values from SAMLResponse querystring parameter (I found this somewhere after googling. So not sure about how it actually works).

ClaimsPrincipal claimsPrincipal = System.Threading.Thread.CurrentPrincipal as ClaimsPrincipal;

Response.Write("Is user Authenticated = " + claimsPrincipal.Identity.IsAuthenticated.ToString());
I get this as : False

Response.Write("   Current Principal  = " + System.Threading.Thread.CurrentPrincipal.ToString());

I get this as : System.Security.Principal.GenericPrincipal

string rawSamlData = Request["SAMLResponse"];
Response.Write("Raw data \n");

rawSamlData = HttpUtility.UrlDecode(rawSamlData);
Response.Write("after url decode \n");

// read the base64 encoded bytes
byte[] samlData = Convert.FromBase64String(rawSamlData);
Response.Write("after base 64 \n");

// read back into a UTF string
string samlAssertion = Encoding.UTF8.GetString(samlData);
Response.Write("saml assertion \n");

All I get is some encrypted string. How can I decode it to SAML response and authenticate the user?
James Walsh Jr 7-Aug-21 15:53pm    
Here is the answer to your same question on Stack Overflow.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900