Ejemplo n.º 1
0
        //TODO: Handle both SAML 1.1 and SAML 2.0
        private static SecurityToken DeserializeToken(string rstrString)
        {
            var        doc     = XDocument.Parse(rstrString);
            XNamespace wstrust = "http://schemas.xmlsoap.org/ws/2005/02/trust";
            var        requestedTokenElement = doc.Root.Element(wstrust + "RequestedSecurityToken");
            XNamespace assertionNs           = "urn:oasis:names:tc:SAML:2.0:assertion";
            var        assertion             = requestedTokenElement.Element(assertionNs + "Assertion");
            var        handler = new Saml2SecurityTokenHandler();

            return(handler.ReadSaml2Token(assertion.ToString()));
        }
        public void GeneratedTokenHasNameId()
        {
            var generator = GetDefaultResponseGenerator();
            var request   = GetDefaultValidatedRequest();
            var response  = generator.GenerateSerializedRstr(request).Result;

            var tokenString = GetTokenString(response);
            var handler     = new Saml2SecurityTokenHandler();
            var token       = handler.ReadSaml2Token(tokenString);
            var nameId      = token.Assertion.Subject.NameId;

            Assert.AreEqual("bob", nameId.Value);
            Assert.AreEqual(Saml2Constants.NameIdentifierFormats.UnspecifiedString, nameId.Format.AbsoluteUri);
        }