Click here to Skip to main content
15,885,829 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
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).

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

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

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

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


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

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

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

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


All I get is some encrypted string. How can I decode it to SAML response and authenticate the user?
Posted
Comments
James Walsh Jr 7-Aug-21 15:53pm    
Here is the answer to your same question on Stack Overflow.
https://stackoverflow.com/questions/39950822/how-do-i-read-a-saml-response

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