Thinktecture.IdentityModel: WRAP and SWT Support

Posted by Your DisplayName here! on Least Privilege See other posts from Least Privilege or by Your DisplayName here!
Published on Sun, 09 May 2010 20:27:46 GMT Indexed on 2010/12/06 17:00 UTC
Read the original article Hit count: 463

Filed under:

The latest drop of Thinktecture.IdentityModel contains some helpers for the Web Resource Authorization Protocol (WRAP) and Simple Web Tokens (SWT).

WRAP
The WrapClient class is a helper to request SWT tokens via WRAP. It supports issuer/key, SWT and SAML input credentials, e.g.:

var client = new WrapClient(wrapEp);
var swt = client.Issue(issuerName, issuerKey, scope);

All Issue overrides return a SimpleWebToken type, which brings me to the next helper class.

SWT
The SimpleWebToken class wraps a SWT token. It combines a number of features:

  • conversion between string format and CLR type representation
  • creation of SWT tokens
  • validation of SWT token
  • projection of SWT token as IClaimsIdentity
  • helpers to embed SWT token in headers and query strings

The following sample code generates a SWT token using the helper class:

private static string CreateSwtToken()
{
    var signingKey = "wA…";
    var audience = "http://websample";
    var issuer = "http://self";
 
    var token = new SimpleWebToken(
      issuer, audience, Convert.FromBase64String(signingKey));

   
token.AddClaim(ClaimTypes.Name, "dominick");
    token.AddClaim(ClaimTypes.Role, "Users");
    token.AddClaim(ClaimTypes.Role, "Administrators");
    token.AddClaim("simple", "test");
 
    return token.ToString();
}

© Least Privilege or respective owner

Related posts about IdentityModel