Search code examples
asp.netasp.net-coreasp.net-identityclaims-based-identity

Latest Compatible Asp.Net Identity


What the latest ASP.Net Identity version I can use in a non-Core .Net?

I'm trying implement role-based claims, and I see that code snippet:

roleManager.AddClaimAsync(...

I did some research, and I discovered "add Claims directly for Roles" is a new feature for ASP.Net Identity Core...

For now, I'm using ASP.Net Identity 2.x (for .Net 4.6). I have some option? The Identity Core needs of .Net Core?


Solution

  • Latest non-Core Identity is 2.2.1, source code for this found on Codeplex.

    If you need to add claims to roles you'll have to implement that yourself - that's not hard: you need to add a table that holds claims, but references Role instead of user - see existing UserClaims table.

    Then when users login you'll have to read all users roles and all claims for them and add them in GenerateUserIdentityAsync, like in this sample.

    Bear in mind that claims are getting overwritten in SecurityStampValidator (sample), so you do need to add claims to the cookie in that method, otherwise you'll loose the extra claims when identity is regenerated.