0
votes

I'm using "IdentityManager.AspNetIdentity" to implement role and claims for an ASP.Net MVC 5.0 Application.

( IdentityManager.AspNetIdentity)

I notice that if create a new role in IdentityManager and I assign it to a specific user, IdentityManager create the role and create a new claim with ClaimType equal to "role".

Picture: Claim Situation

Now... Correct me if I'm wrong:

From MVC Application side, I know that by default, the framework tests the **ClaimType = "

http: //schemas.microsoft.com/ws/2008/06/identity/claims/role

"** in order to implement security when checking security.

Picture: Workaround

Now my solution in order to make IdentityManager and the MVC Application working with same role is to add claims with the ClaimType equal to the Microsoft Schema.

But how can I let the IdentityManager fill the ClaimType with the Microsoft Schema instead of "role" each time I assign a role to a user?

Or on the other side, How can I make Microsoft.Identity2.0 to test "role" ClaimType instead of the schema when testing the role of the user?

Thanks to support

1

1 Answers

0
votes

Add a RoleClaimType to the AspNetIdentityManagerService in your Startup.cs:

public class ApplicationIdentityManagerService : 
    AspNetIdentityManagerService<ApplicationUser, string, IdentityRole, string>
{
    public ApplicationIdentityManagerService(ApplicationUserManager userMgr, ApplicationRoleManager roleMgr)
        : base(userMgr, roleMgr)
    {
        RoleClaimType = System.Security.Claims.ClaimTypes.Role;//or streight RoleClaimType = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
    }

}

And now IdentityManager work with the Microsoft Schema ("http://schemas.microsoft.com/ws/2008/06/identity/claims/role")

Note ClaimTypes.Role is from System.Security.Claims not from IdentityManager.Constants