title: How to convert SAML XML token string to either SecurityToken or ClaimsPrincipal instance?
body: <h3>My context:</h3>
  
  <ul>
  <li>.Net RESTful web service</li>
  <li>Client (mixed platforms, technologies, lib capabilities) has obtained a SAML token</li>
  <li>Trying to accept the token for authentication/authorization in the REST service
  
  <ul>
  <li>in HTTP Authorization / X-Authorization header</li>
  <li>as query parameter</li>
  </ul></li>
  <li>Will also support SWT later, but need to get SAML tokens going</li>
  </ul>
  
  <h3>Details:</h3>
  
  <p>I have a SAML token in a string:</p>
  
  <pre><code>&lt;saml:Assertion xmlns:saml="..." ...&gt; ..etc... &lt;/&gt;
  </code></pre>
  
  <p>In an HttpModule, I want to convert this into a ClaimsPrincipal so that my service can do the usual Thread.CurrentPrincipal as IClaimsPrincipal stuff.</p>
  
  <p>I found a couple enticing pages/blogs/etc... that looked helpful:  </p>
  
  <ul>
  <li><a href="http://weblogs.asp.net/cibrax/archive/2009/03/06/brokered-authentication-for-rest-active-clients-with-saml.aspx" rel="noreferrer">Cibrax's Idea for passing the token in the HTTP Authorization header</a></li>
  <li><a href="http://www.leastprivilege.com/SecuringWCFDataServicesUsingWIF.aspx" rel="noreferrer">Dominick Baier on something similar for SWT, with mention of easily doing same for SAML</a></li>
  </ul>
  
  <p>I'm stuck literally trying to turn the SAML token into the ClaimsPrincipal (via SecurityToken intermediate step or direct... happy either way).  The sample code from Cibrax's idea uses the following for the crucial verification and deserialization step:  </p>
  
  <pre><code>SecurityTokenSerializer securityTokenSerializer 
      = new SecurityTokenSerializerAdapter(
          FederatedAuthentication.SecurityTokenHandlers, 
          MessageSecurityVersion.Default.SecurityVersion, 
          false, new SamlSerializer(), null, null);
  
  SecurityToken theToken 
      = WSFederationAuthenticationModule.GetSecurityToken(
          theSamlTokenInStringForm, securityTokenSerializer);
  </code></pre>
  
  <p>The wall I've hit is that the RTM version of WIF does not expose this overload of GetSecurityToken...   it only exposes:  </p>
  
  <pre><code>WSFederationAuthenticationModule fam = new WSFederationAuthenticationModule();
  SecurityToken theToken = fam.GetSecurityToken(HttpRequest theRequest);
  SecurityToken theToken = fam.GetSecurityToken(SignInResponseMessage message);
  </code></pre>
  
  <p>Thanks for helping me to get unstuck!</p>
  
  <p>Tyler</p>