【问题标题】:Identity Server 4 how to map list of role into MVC applicationIdentity Server 4 如何将角色列表映射到 MVC 应用程序
【发布时间】:2019-09-03 07:24:53
【问题描述】:

在 Identity Server 4 中,我为用户创建角色声明“Admin”:

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

在客户端应用程序中,我映射了这个角色,它只适用于一个角色:

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();
}

但我需要映射角色列表但我不知道如何创建声明并映射到 asp net core mvc 应用程序?

[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

【问题讨论】:

    标签: asp.net-mvc asp.net-core identityserver4


    【解决方案1】:

    只需以数组方式添加Claim

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-15
      • 2019-09-20
      • 2015-04-12
      • 2021-03-18
      • 2018-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多