protected void Page_Load(object sender, EventArgs e) { if (Request.Form["SAMLResponse"] != null) { if (Request.Form["RelayState"] == "testvalidate") { testconfiguration(); } else { try { Saml.Saml_Response samlResponse = new Saml_Response(samlCertificate, idp_sso_target_url, false); samlResponse.LoadXmlFromBase64(Request.Form["SAMLResponse"]); //SAML providers usually POST the data here if (samlResponse.IsValid()) { string username, email, firstname, lastname; username = samlResponse.GetNameID(); firstname = samlResponse.getAttr(ConfigurationManager.AppSettings["first_name"]); lastname = samlResponse.getAttr(ConfigurationManager.AppSettings["last_name"]); try { if (ConfigurationManager.AppSettings["email_id"] == "NameID") { email = samlResponse.GetNameID(); } else { email = samlResponse.getAttr(ConfigurationManager.AppSettings["email_id"]); } sendpost(username, email, firstname, lastname); } catch (ThreadAbortException texc) { //handle the exception if you want } } } catch (InvalidDataException ex) { string URLAuth = ConfigurationManager.AppSettings["user_url"].Trim(); HttpContext.Current.Response.Redirect(URLAuth + "?error=" + ex.Message); } } } else { FormsAuthentication.RedirectToLoginPage(); } // Response.Write("Request:" + Request.Form["SAMLResponse"]); }
private void testconfiguration() { string ent_id = ""; Saml.Saml_Response samlResponse = null; if (Request.Form["SAMLResponse"] != null) { try { samlResponse = new Saml_Response(samlCertificate, idp_sso_target_url, true); samlResponse.LoadXmlFromBase64(Request.Form["SAMLResponse"]); //SAML providers usually POST the data here if (samlResponse.IsValid()) { //string username, email, firstname, lastname, emailid, name_attr, email_attr, first_attr, last_attr,show; Label2.Text = "NameID "; Label3.Text = samlResponse.GetNameID(); Label1.Text = samlResponse.GetAttributes(); this.test_result = "SUCCESSFUL"; } } catch (InvalidDataException ex) { this.test_result = "FAILED"; string err = cst.RetError(ex.Message); if (ex.Message == "invalid+issuer_id") { err += samlResponse.ent_id; } this.response_error = err; } } }