【问题标题】:Role based claims in Identity Server 3 + AspNet IdentityIdentity Server 3 + AspNet Identity 中基于角色的声明
【发布时间】:2016-02-28 02:01:40
【问题描述】:

我正在使用带有 AspNet Identity 用户服务实现的 ASP.NET 5 beta 8 和 Identity Server 3。默认情况下,AspNet Identity 提供名为 AspNetRoleClaims 的表,这对我的情况来说看起来不错。我的系统中有不同的角色,每个角色都有一些权限,我想将其作为声明来实现。所以每个角色都会有一组声明。

我在 Internet 上没有找到任何使用 AspNetRoleClaims 表的示例,所以最好只创建我自己的表和实现?

处理角色权限的最佳做法是什么?

提前致谢! 塞尔吉。

【问题讨论】:

    标签: c# asp.net asp.net-identity asp.net-core identityserver3


    【解决方案1】:

    塞尔吉,

    我一直在寻找类似的东西,看起来所有的角色信息,包括 RoleClaims 都是在角色管理器中使用 GetClaimsAsync、AddClaimAsync、RemoveClaimAsync 方法处理的。您可以在此处查看 ASP 身份代码: https://github.com/aspnet/Identity/blob/dev/src/Microsoft.AspNet.Identity/RoleManager.cs

    在角色管理器中,我可以管理角色。示例:

    创建角色

    await RoleManager.CreateAsync(new IdentityRole { Name = "Test" });

    创建角色声明

    var roleResult = await RoleManager.AddClaimAsync(role, new Claim("Dashboard", "Read"));

    然后检查您现在使用的策略和要求的角色或声明。这篇文章很好地解释了事情。

    http://leastprivilege.com/2015/10/12/the-state-of-security-in-asp-net-5-and-mvc-6-authorization/

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      • 2019-04-11
      • 2019-04-22
      • 1970-01-01
      • 2017-02-11
      • 1970-01-01
      • 2021-07-18
      相关资源
      最近更新 更多