2

I am using this code in CALLback url using SUstainsys.SAaml2 library:

 public ActionResult Callback()
    {

        var samlToken = (Saml2SecurityToken)null;
        var samlResponses =  HttpContext.Request.Form["SAMLResponse"];  HttpContext.Current.Request.Form["SAMLResponse"]; or elsewhere.
        //if (form.Count() > 0)
        //{
        //    var samlResponses = form.GetValues("SAMLResponse");
            if (samlResponses != null)
            {
                foreach (var samlResponse in samlResponses)
                {
                    try
                    {
                        var decodedSamlResponse = Convert.FromBase64String(samlResponse.ToString());
                        var reader = XmlReader.Create(new MemoryStream(decodedSamlResponse));
                        var serializer = new XmlSerializer(typeof(XmlElement));
                        var samlResponseElement = (XmlElement)serializer.Deserialize(reader);
                        var manager = new XmlNamespaceManager(samlResponseElement.OwnerDocument.NameTable);
                        manager.AddNamespace("saml2", "urn:oasis:names:tc:SAML:2.0:assertion");
                        var assertion = (XmlElement)samlResponseElement.SelectSingleNode("//saml2:Assertion", manager);
                    //var samltoken= Options.FromConfiguration.SPOptions.Saml2PSecurityTokenHandler.ReadToken(XmlReader.Create(new StringReader(assertion.OuterXml)));
                    samlToken = (Saml2SecurityToken)Options.FromConfiguration.SPOptions.Saml2PSecurityTokenHandler.ReadToken(XmlReader.Create(new StringReader(assertion.OuterXml)));
                        break;
                    }
                    catch { }
                }
            }
        ViewBag.SamlResponse = samlResponses;
        ViewBag.SamlToken = samlToken;
        return View();
    }

       

But I am getting null in SAML Response.

mybrave
  • 1,662
  • 3
  • 20
  • 37

1 Answers1

0

That functionality is built into the AcsCommand, you shouldn't do it yourself.

Look at the samples in the repo and use the HttpModule, Mvc Controller or Owin middleware (depending on what kind of application you have).

Anders Abel
  • 67,989
  • 17
  • 150
  • 217
  • Hi Abel, Actual problem is : – Hitanshu Sharma Apr 25 '19 at 04:24
  • I am new to SAML. Requirement is to get SAML token from SAML Response in controller action method and to pass that token to ImanageClient. Can you help me in this how I can get SAML token from SAML response in c#. The above code is not working as I am not getting response in request.form. Instead I can check SAMl response in chrome extention tool.Please help!! – Hitanshu Sharma Apr 30 '19 at 06:14
  • @HitanshuSharma did you ever figure this out? I'm trying to do the same thing. – JasonV Oct 08 '19 at 15:45