Wednesday, January 1, 2014

Windows Identity Foundation

http://dotnetcodr.com/tag/claims/page/2/

How to create a Claim
      Claim claim1 = new Claim("Name", "User1");

You can also use enumeration ClaimTypes offered by WIF to give name for the claim (This is not actually a enum. It is a static class with const fields).

     Claim claim2 = new Claim(ClaimTypes.Country, "Sri Lanka");

You can create IIdentity object using set of claims easily.

            Claim claim1 = new Claim(ClaimTypes.Name, "User");
            Claim claim2 = new Claim(ClaimTypes.Country, "Sri Lanka");
            IList<Claim> claims = new List<Claim> { claim1, claim2 };

            ClaimsIdentity claimsIdentity = new ClaimsIdentity(claims);

If you look at the source of ClaimsIdentity class, you can see that DefaultIssuer of this class is "LOCAL AUTHORITY". You need to give authentication type to make ClaimsIdentity authenticated (see here). 

After creating ClaimsIdentity you can create ClaimsPrincipal which wraps Identity object. 

     ClaimsPrincipal principal = new ClaimsPrincipal(claimsIdentity);

Since ClaimsPrincipal implements IPrincipal, you can set Thread.CurrentPrincipal or HttpContext.User to principal object (check this, HttpContext User vs Thread CurrentPrincipal and Thread CurrentPrincipal Identity vs HttpContext User Identity). 

Claims Transformation


Membership.ValidateUser 

validates against Membership provider defines inside web.config


Also you can go through this wondeful 7 hour workshop about WIF.



Resources

2 comments:

  1. http://stackoverflow.com/questions/21807535/net-claims-auth-unable-to-set-current-principal?lq=1 also check videos there.

    ReplyDelete
  2. https://msdn.microsoft.com/en-us/library/hh545457.aspx

    ReplyDelete

Powered by Blogger.


Software Architect at Surge Global/ Certified Scrum Master

Experienced in Product Design, Software Engineering, Team management and Practicing Agile methodologies.

Search This Blog

Facebook