Для заявок на контент в id_token IdentityServer4 соответствует DefaultClaimsService
(реализация по умолчанию интерфейса IClaimsService
).
Для определения набора утверждений используются типы утверждений, включенные в область действия профиля.
Чтобы справиться с этим, просто определите свое собственное IdentityResource
, установите для его свойства Name
значение IdentityServerConstants.StandardScopes.Profile
и передайте метод конфигурации IdentityResources (например, AddInMemoryIdentityResources()
) вместо стандартного IdentityResources.Profile
.
Вот пример такого IdentityResource:
public class ProfileIdentityResource : IdentityResource
{
public ProfileIdentityResource()
{
Name = IdentityServerConstants.StandardScopes.Profile;
DisplayName = "User profile";
Description = "Identity resource which defines IdentityToken content";
Emphasize = true;
// claims, which should be added to IdentityToken
UserClaims = new string[]
{
// standard
JwtClaimTypes.Name,
JwtClaimTypes.Role,
JwtClaimTypes.Email,
// custom
JwtAdditionalClaimTypes.Login,
JwtAdditionalClaimTypes.Division,
JwtAdditionalClaimTypes.DivisionId,
...
};
}
}