'SAML2 Authentication using ASP.NET with ADFS Federation meta data
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.
Solution 1:[1]
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);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Amit |