Scope 和 Claim (Scopes and Claims)

IdentityServer.Core.Models.Scope 类是对 OpenID Connect 或 OAuth2 scope 的建模。

Scope 也可以将 claim 指定到对应的 token 中—— ScopeClaim 类有以下的属性:

role identity scope 示例:

var roleScope = new Scope
{
    Name = "roles",
    DisplayName = "Roles",
    Description = "Your organizational roles",
    Type = ScopeType.Identity,

    Claims = new List<ScopeClaim>
    {
        new ScopeClaim(Constants.ClaimTypes.Role, alwaysInclude: true)
    }
};

‘AlwaysIncludeInIdentityToken’ 属性用于指定某个特定的 claim 应该总是为 identity token 的一部分,即使为 userinfo endpoint 请求了 access token 。

一个 IdentityManager API 的 scope 示例:

var idMgrScope = new Scope
{
    Name = "idmgr",
    DisplayName = "IdentityManager",
    Type = ScopeType.Resource,
    Emphasize = true,

    Claims = new List<ScopeClaim>
    {
        new ScopeClaim(Constants.ClaimTypes.Name),
        new ScopeClaim(Constants.ClaimTypes.Role)
    }
};