【问题标题】:IdentityServer4 and UserInfo endpoint customizationIdentityServer4 和 UserInfo 端点自定义
【发布时间】:2019-10-03 23:22:23
【问题描述】:

我创建了一个 IdentityServer4 应用程序,如果我在该应用程序中登录,用户声称一切正常。如果我从另一个客户端应用程序 (MVC) 登录,则 UserInfo 端点不会返回相同的声明。

IdentityServer 配置了 ASP.NET Identity,因此 UserProfile 已经配置为返回所有 UserClaims,就像我创建的一样。

我不明白为什么它没有显示在同意视图中,或者它没有包含在 UserInfo 端点结果中

【问题讨论】:

  • 只有在 oidc 请求中请求了适当的范围时才会返回一些声明。
  • 我请求了带有所需声明的自定义范围,我将它们放在本地主体中,但 userinfo 端点没有返回它们。
  • 您需要添加更多信息,在不了解完整问题的情况下很难帮助您

标签: c# asp.net-core openid identityserver4


【解决方案1】:

请检查以下几点是否可以解决您的问题

1.) 您的身份资源和 API 资源应具有所需的 UserClaims。

2.) 检查是否有一些自定义逻辑可以为您的配置文件服务中的 userinfo 端点发出请求的声明。

public class ProfileService : IProfileService
{
    public async Task GetProfileDataAsync(ProfileDataRequestContext context)
    {
        if (context.Caller == IdentityServerConstants.ProfileDataCallers.UserInfoEndpoint)
        { 
            //custom logic to add requested claims 
            context.AddRequestedClaims(claims);
        }
    }
}

3.) 尝试在 MVC 客户端 AddOpenIdConnect 配置中设置属性“GetClaimsFromUserInfoEndpoint=true”。

【讨论】:

    【解决方案2】:

    您是否配置了您的IdentityResources? 比如:

    services.AddIdentityServer()
    
                    .AddInMemoryIdentityResources(GetIdentityResources())
    
    //where
    public static List<IdentityResource> GetIdentityResources()
    {
      // Claims automatically included in OpenId scope
      var openIdScope = new IdentityResources.OpenId();
      openIdScope.UserClaims.Add(JwtClaimTypes.Locale);
    
      // Available scopes
      return new List<IdentityResource>
      {
        openIdScope,
        new IdentityResources.Profile(),
        new IdentityResources.Email(),
        new IdentityResource(Constants.RolesScopeType, Constants.RolesScopeType,
          new List<string> {JwtClaimTypes.Role, Constants.TenantIdClaimType})
          {
            //when false (default), the user can deselect the scope on consent screen
            Required = true 
          }
      };
    }
    

    【讨论】:

      猜你喜欢
      • 2017-09-13
      • 2021-09-05
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多