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);
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
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.
WIF Code Samples provided by MSDN.
Latest release of ASP.NET Identity 2.0.0
http://blogs.msdn.com/b/webdev/archive/2014/03/20/test-announcing-rtm-of-asp-net-identity-2-0-0.aspx
Latest release of ASP.NET Identity 2.0.0
http://blogs.msdn.com/b/webdev/archive/2014/03/20/test-announcing-rtm-of-asp-net-identity-2-0-0.aspx
Resources
http://stackoverflow.com/questions/21807535/net-claims-auth-unable-to-set-current-principal?lq=1 also check videos there.
ReplyDeletehttps://msdn.microsoft.com/en-us/library/hh545457.aspx
ReplyDelete