As I have been here, I believe many more people still find trouble with this question.
Identity Framework is basic and complete, you can basically build a complex app often without having to extend it's underlying model. Keep it simple stupid:
Roles are roles, claims are claims but what exactly does the RoleClaim
table store? Well it stores claims for a particular role. And those claims can basically be permissions. Keep it that simple. Here's an example:
Have Predefined Permissions in a dictionary like this:
public static class PredefinedClaims
{
public static dynamic Get = new Dictionary<string,Claim>{
{"PermissionToWrite", new Claim("PermissionToWrite","Write") },
{"PermissionToRead", new Claim("PermissionToWrite","Read") },
};
}
And let's assume you have a role called User
with Id=1
. You can create permissions by simply associating that role with claims. Like this:
var GrantPermissions= new List<RoleClaim>(){
new RoleClaim{
RoleId = 1,
PredefinedClaims.Get()["PermissionToWrite"].ClaimType, // <= Set the Permission Type
PredefinedClaims.Get()["PermissionToWrite"].ClaimType // <= Granted Edit rights.
},
// Add more roleclaims intances here
}
And then you can persist the GrantPermissions
to your database and they'll be added to your identity. All you need to do is follow the normal procedure of registering your claims to your policies within startup.cs.