0
votes

In Identity Server 4, I create role claim "Admin" for a user :

userMgr.AddClaimsAsync(user, 
new Claim[]{ new Claim("role", "Admin") })

In client application I map this role and it works fine for only one role:

options.Scope.Add(RSIdentityServerConstants.Roles);
options.ClaimActions.MapJsonKey("role", "role", "role");
options.TokenValidationParameters.NameClaimType = "name";
options.TokenValidationParameters.RoleClaimType = "role";

[Authorize(Roles = "Admin")]  => Works fine
public IActionResult Index()
{
  return View();
}

But I need to map a list of role but I don't know How to create the claim and map to the asp net core mvc application?

[Authorize(Roles = "Admin, SuperAdmin, Others")]  => How to do ??
public IActionResult Index()
{
  return View();
}

userMgr.AddClaimsAsync(user, 
new Claim[]{ new Claim("role", "Admin, SuperAdmin, Others") })  => this doesn't work
1

1 Answers

2
votes

Just add the Claim in an array fashion:

new Claim[]{ new Claim("role", "Admin"), new Claim("role", "SuperAdmin"), ...  })