Scopes and Claims

The IdentityServer.Core.Models.Scope class models an OpenID Connect or OAuth2 scope.

Scope can also specify claims that go into the corresponding token - the ScopeClaim class has the following properties:

Example of a 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)
    }
};

The ‘AlwaysIncludeInIdentityToken’ property specifies that a certain claim should always be part of the identity token, even when an access token for the userinfo endpoint is requested.

Example of a scope for the IdentityManager API:

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