В IdentityServer4 я определил IdentityResource с некоторыми утверждениями:
new IdentityResource {
Name = "userdata",
UserClaims = new List<string> {
JwtClaimTypes.Subject,
JwtClaimTypes.Role,
JwtClaimTypes.Email,
JwtClaimTypes.Name
}
}
И затем добавьте его в области в конфигурации клиента:
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
"api1",
"userdata"
}
В клиентском приложении, которое я запросилэта область действия:
.AddOpenIdConnect("oidc", options => {
options.Scope.Add("openid");
options.Scope.Add("userdata");
options.Scope.Add("offline_access");
options.Scope.Add("api1");
}
В IS4 я реализовал IProfileService , чтобы добавить некоторые утверждения в id_token.
public async Task GetProfileDataAsync(ProfileDataRequestContext context) {
var sub = context.Subject.GetSubjectId();
var user = await _userManager.FindByIdAsync(sub);
if (user == null) {
throw new ArgumentException("");
}
var principal = await _claimsFactory.CreateAsync(user);
var userClaims = principal.Claims.ToList();
var claims = new List<Claim> {
userClaims.Find(x => x.Type == JwtClaimTypes.Subject),
userClaims.Find(x => x.Type == JwtClaimTypes.Role),
userClaims.Find(x => x.Type == JwtClaimTypes.Email),
userClaims.Find(x => x.Type == JwtClaimTypes.Name),
new Claim("iesseapetenantid", user.TenantId.ToString())
};
var requestedClaimTypes = context.RequestedClaimTypes;
context.AddRequestedClaims(claims);
}
context.AddRequestedClaims(claims)
отфильтровать принятые утверждения и добавитьтолько те, которые были запрошены клиентом.
Проблема в том, что в context.RequestedClaimTypes
требование sub отсутствует, но есть три других: email , имя и роль .
Почему пропадает требование "sub"?
Спасибо!