예제 #1
0
        private string ParseSAMLResponse(string strResponse)
        {
            var strPatientURL = queryParameters.FirstOrDefault(i => i.Key == "patientUrl").Value;
            var sb            = new StringBuilder();
            var xml           = new XmlDocument();

            xml.LoadXml(Util.DecodeBase64(strResponse));
            var samlResponse = new SAMLResponse(xml.DocumentElement);

            File.WriteAllText("SAMLResponse.xml", samlResponse.ToString());

            foreach (SAMLAssertion samlAssertion in samlResponse.Assertions)
            {
                foreach (var attributeStatement in samlAssertion.GetAttributeStatements())
                {
                    foreach (SAMLAttribute samlAttribute in attributeStatement.Attributes)
                    {
                        if (samlAttribute.Name != "idptoken")
                        {
                            continue;
                        }

                        sb.Append(strPatientURL);
                        sb.Append("&idptoken=");
                        sb.Append(samlAttribute.Values.FirstOrDefault());
                    }
                }
            }

            return(sb.ToString());
        }
예제 #2
0
        /// <summary>
        /// This Get Action is used to Generate and POST the SAML Repsonse
        /// based on a supplied AuthN Request
        /// </summary>
        public void OnGet(String SAMLRequest, String RelayState)
        {
            this.RelayState = RelayState;

            String              sml   = SAMLHelper.Decompress(SAMLRequest);
            XmlDocument         doc   = new XmlDocument();
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);

            nsmgr.AddNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
            nsmgr.AddNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
            doc.LoadXml(sml);
            XmlElement root = doc.DocumentElement;

            ACS = root.SelectSingleNode("/samlp:AuthnRequest/@AssertionConsumerServiceURL", nsmgr).Value;
            ID  = root.SelectSingleNode("/samlp:AuthnRequest/@ID", nsmgr).Value;

            string       httpors = HttpContext.Request.IsHttps ? "https://" : "http://";
            string       thisurl = httpors + HttpContext.Request.Host.Value;
            SAMLResponse Resp    = new SAMLResponse(ACS, ID, thisurl, _configuration);

            this.SAMLResponse = Convert.ToBase64String(Encoding.UTF8.GetBytes(Resp.ToString()));
            this.RelayState   = RelayState;
        }
예제 #3
0
        /// <summary>
        /// This Post Action is used to Generate and POST the SAML Repsonse for and IDP initiated SSO
        /// </summary>
        public IActionResult OnPost(string Tenant, string Policy)
        {
            string b2cloginurl = _configuration["SAMLTEST:b2cloginurl"];

            Policy = Policy.StartsWith("B2C_1A_") ? Policy : "B2C_1A_" + Policy;

            string ACS = "https://" + b2cloginurl + "/te/" + Tenant + ".onmicrosoft.com/" + Policy + "/samlp/sso/assertionconsumer";

            SAMLResponse Resp         = new SAMLResponse(ACS, "", SAMLHelper.GetThisURL(this), _configuration);
            string       SAMLResponse = Convert.ToBase64String(Encoding.UTF8.GetBytes(Resp.ToString()));

            return(Content(SAMLHelper.GeneratePost(SAMLResponse, ACS), "text/html"));
        }