Thursday, 27 January 2011

XML from WIF SecurityToken

If you ever need to see the XML in a SecurityToken (in my case a SamlSecurityToken) then you have to write it out using a XmlWriter:

            var sth = new Microsoft.IdentityModel.Tokens.Saml11.Saml11SecurityTokenHandler();
            var ms = new MemoryStream();
            var writer = XmlWriter.Create(ms);
            sth.WriteToken(writer, token);
            writer.Flush();
            ms.Seek(0, SeekOrigin.Begin);
            var xml = new StreamReader(ms).ReadLine();


where token is a SecurityToken object (System.IdentityModel.Tokens).

No comments:

Post a Comment