【问题标题】:Providing access to User Groups using Identity Server 3使用 Identity Server 3 提供对用户组的访问
【发布时间】:2017-04-20 16:40:16
【问题描述】:

我目前正在开发的应用程序是一个巨大的 ASP.NET MVC Web 应用程序,它使用传统的 Windows 身份验证模型。我们正在尝试使用 Identity Server 3 和 Open ID Connect 迁移到单点登录模型。

关于我的问题,在使用 Identity Server 时,是否有任何方法/解决方法可以在用户组的基础上提供访问权限?这里的问题是我的用户组可能是基于角色的或 Active Directory 组。我正在寻找类似 InMemoryGroup 的东西(类似于 InMemoryUser)。

为可以基于角色或不基于角色的用户组模仿以下内容:

new InMemoryUser
            {
                Username = "harry",
                Password = "thisispassword@123",
                Subject = "1",
                Claims = new Claim[]
                {
                    new Claim(Constants.ClaimTypes.Name, "Harry Potter"),
                    new Claim(Constants.ClaimTypes.GivenName, "Harry"),
                    new Claim(Constants.ClaimTypes.FamilyName, "Potter"),
                    new Claim(Constants.ClaimTypes.Email, "harry.potter@hogwarts.com"),
                    new Claim(Constants.ClaimTypes.EmailVerified, "true", ClaimValueTypes.Boolean),
                    new Claim(Constants.ClaimTypes.Role, "Administrator"),
                }
            }

我对 Identity Server 和 Open ID Connect 比较陌生,无法在线找到任何东西,非常感谢任何线索。

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 asp.net-web-api identityserver3 openid-connect


    【解决方案1】:

    要表示用户是组的成员,您只需添加声明即可。您可以添加:

    new Claim("Group", "Hogwarts Student")
    

    给你的内存用户。该声明表明哈利是“霍格沃茨学生”组织的成员。您需要注意一些事情。被调用的构造函数是:

    new Claim(string claimType, string claimValue)
    

    Identity Server 在 Constants 类中提供了一些标准的,但您可以自己制作。此外,您可以拥有多个群组声明,因此您可以拥有

    new Claim("Group", "Hogwarts Student"),
    new Claim("Group", "Gryffindor House)
    

    如果您想查看 Harry 是否在“Gryffindor House”组中,您只需搜索声明类型等于“Group”且声明值等于“Gryffindor House”的声明列表.

    最后,组和角色之间的区别通常更多的是应用程序语义问题,而不是它们存储方式的物理差异。通常,可以为应用程序执行“管理员”角色的用户集只是一组用户。应用程序对待组中用户的方式使组成为角色。

    【讨论】:

    • 适用于我的用例 :) 接受作为答案
    猜你喜欢
    • 2018-09-20
    • 1970-01-01
    • 2017-08-02
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 2018-02-21
    • 1970-01-01
    • 2015-04-08
    相关资源
    最近更新 更多