Exemple #1
0
        private static string SerializeBase(RequestSecurityTokenResponse rstr)
        {
            var sb       = new StringBuilder();
            var settings = new XmlWriterSettings();

            using (var writer = XmlWriter.Create(sb, settings))
            {
                var serializer = new XmlSerializer(typeof(RequestSecurityTokenResponse));
                serializer.Serialize(writer, rstr);
            }
            return(sb.ToString());
        }
Exemple #2
0
        //TODO: Serialize the token
        public static string Serialize(RequestSecurityTokenResponse rstr)
        {
            var rstrString = SerializeBase(rstr);

            var handler      = new Saml2SecurityTokenHandler();
            var token        = handler.WriteToken(rstr.RequestedSecurityToken);
            var tokenElement = XElement.Parse(token, LoadOptions.None);

            XNamespace wstrust = "http://schemas.xmlsoap.org/ws/2005/02/trust";
            var        requestedTokenElement = new XElement(wstrust + "RequestedSecurityToken");

            requestedTokenElement.Add(tokenElement);

            var        doc       = XDocument.Parse(rstrString);
            XNamespace policy    = "http://schemas.xmlsoap.org/ws/2004/09/policy";
            var        appliesTo = doc.Root.Element(policy + "AppliesTo");

            appliesTo.AddAfterSelf(requestedTokenElement);
            return(doc.ToString(SaveOptions.DisableFormatting));
        }