Example #1
0
        public static SamlResponseResult ValidateAndGetUserIDResponseDoc(XmlDocument xmlDoc)
        {
            SamlResponseResult result = new SamlResponseResult();

            xmlDoc.NullCheck("xmlDoc");

            string userID = string.Empty;

            XmlNamespaceManager ns = new XmlNamespaceManager(xmlDoc.NameTable);
            ns.AddNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
            ns.AddNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
            ns.AddNamespace("x", "http://www.w3.org/2000/09/xmldsig#");

            XmlElement signatureElem = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("//x:Signature", ns);

            if (signatureElem != null)
            {
                XmlElement assertionNode = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("saml:Assertion", ns);

                if (assertionNode != null)
                {
                    SignedXml signedXml = new SignedXml(assertionNode);

                    signedXml.LoadXml(signatureElem);

                    X509Certificate2 certificate = GetEmbededPublicCertificate();

                    result.ValidateResult = signedXml.CheckSignature(certificate, true);

                    result.UserID = assertionNode.GetSingleNodeText("saml:Subject/saml:NameID", ns);
                    result.ReturnUrl = assertionNode.GetSingleNodeText("saml:AttributeStatement/saml:Attribute[@Name='source']/saml:AttributeValue", ns);
                }
            }

            return result;
        }
Example #2
0
		public void FromXml(XmlDocument xmlDoc)
		{
			xmlDoc.NullCheck("xmlDoc");

			FromXmlElement(xmlDoc.DocumentElement);
		}