Saml2SecurityToken to XmlElement RRS feed

  • Question

  • I have my own library that returns an object of type Microsoft.IdentityModel.Tokens.Saml2.Saml2SecurityToken using WIF API. But I want to get token as XML string or XmlElement. 

    How can I get entire token XML from Saml2SecurityToken object?

    Saturday, January 15, 2011 6:59 PM


  • You can use the SAML security token handler's WriteToken method. This writes to an XmlWriter. Then convert this to a string.



    var sb = new StringBuilder(128);
    handler.WriteToken(new XmlTextWriter(new StringWriter(sb)), token);


    Dominick Baier | thinktecture | http://www.leastprivilege.com
    • Marked as answer by Maulik Patel Monday, January 17, 2011 2:29 PM
    Saturday, January 15, 2011 9:34 PM