Identity Server 4:IProfileService.GetProfileDataAsync 中的 RequestedClaimTypes 不包括 IdentityResourceClaims

Identity Server 4: RequestedClaimTypes in IProfileService.GetProfileDataAsync not including IdentityResourceClaims

我已经创建了我自己的 ProfileService 具体,基于内置的。

在 GetProfileDataAsync() 中,context.RequestedClaimTypes 不包括来自 IdentityResourceClaims table 的任何相关声明,但它确实具有来自 context.RequestedResources.ParsedScopes 中指定范围的 IdentityResource。我认为与这些范围关联的声明应该包含在 RequestedClaimTypes 中,否则有没有办法从上下文中获取这些声明?或者我需要做我自己的数据库查询吗?

这个例子 - “app_perms”是范围(身份资源),“app”是相关声明(在 IdentityResourceClaims table 中)

    protected virtual async Task GetProfileDataAsync(ProfileDataRequestContext context, IdentityUser user)
    {
        // since not including claims for IdentityResource scopes, need to check the scope
        if (context.RequestedResources.ParsedScopes.Any(x => x.ParsedName == "app_perms") || context.RequestedClaimTypes.Contains("app"))
        {
            // add some test app claims 
            context.IssuedClaims.Add(new Claim("app", "App1"));
            context.IssuedClaims.Add(new Claim("app", "App2"));
        }
    }

我的印象是,您只需在 GetProfileDataAsync 中设置所有可用的声明,然后让 IdentityServer 决定哪些声明应该在不同的地方结束(id/access 令牌、用户信息....)

这也简化了 IProfileService 的实现

实际上它们可以在这里找到: context.RequestedResources.Resources.IdentityResources.Any(x => x.UserClaims.ContainsIgnoreCaseTrim("角色"))