0

I am trying to implement the SAML2 authentication from ASP.NET Web Application(SP)(.Net Framework 4.0) with ADFS(IdP). I had integrated SAML2.o nugget and tried to many ways to get the credential inputs from HTML form and Post the SAML Response. But unable to display the input form and get the SAML Response?

Here is my sample source code : (I have implement the HTTP Post Binding)

StringBuilder sb = new StringBuilder();
Saml20AuthnRequest samlRequest = ADFSRequest.GetDefault();
samlRequest.Request.Destination = ConfigurationManager.AppSettings["IdentityProviderUrl"];
samlRequest.Request.AssertionConsumerServiceUrl = ConfigurationManager.AppSettings["ServiceProviderUrl"];
                    sb.Append(string.Format("{0}wia?SAMLRequest=",ConfigurationManager.AppSettings["IdentityProviderUrl"]));
                    sb.Append(HttpUtility.UrlEncode(Convert.ToBase64String(Encoding.UTF8.GetBytes(samlRequest.GetXml().OuterXml))));
                    sb.Append("&client-request-id=").Append(samlRequest.Id);
                    HttpContext.Current.Response.Redirect(sb.ToString(),false);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();

Anyone can help to implement the SAML2 in ASP.Net application? Note: I don’t want to use any thirty-part tools and open source is fine.

TBA
  • 1,921
  • 4
  • 13
  • 26

1 Answers1

0
                 this worked for me for azure setup

                 using (StreamReader inputStream = new StreamReader(context.Request.InputStream))
                    {
                        assertionXml = inputStream.ReadToEnd();
                    }
                    NameValueCollection formcollectiom = HttpUtility.ParseQueryString(assertionXml);
                    JObject result = new JObject();
                    try
                    {

                        string response = formcollectiom["SAMLResponse"];
                        assertionXml = System.Text.UTF8Encoding.UTF8.GetString(Convert.FromBase64String(response));
                
                        Dictionary<string, string> requestAttributes = new Dictionary<string, string>();
                        //add your custom Attributes here 
                        
                        result = SAMLHelper.verifyAssertion(assertionXml, "IDP_Issuer", consumerEndPoint, IDP_Issuer_Certificate, requestAttributes);
                       
                    }
Amit
  • 75
  • 7
  • Thank you the update. But I am using ADFS with federation meta data and its a xml file. So we have attached this security file and needs to send to ADFS and get it response. So above you example not suitable for my authentication scenario – Murugan Kathiresan May 08 '22 at 02:12