【问题标题】:IdentityServer4 - 'sub' claim is missingIdentityServer4 - 缺少“子”声明
【发布时间】:2018-04-24 04:19:50
【问题描述】:

我创建了一个示例 MVC 应用程序,它使用身份服务器对 Google 进行身份验证。身份验证工作正常,但是当响应返回时,它缺少“子”声明并最终出现“缺少子声明”的错误。

我读了几篇关于将名称标识符映射到子的声明映射的文章。但不知道如何做到这一点。有一些博客说通知谷歌发出子声明。但又不知道该怎么做。

期待一些帮助!

【问题讨论】:

  • 你有没有解决这个问题@HimalPatel?面对同样的事情,似乎没有任何配置可以改变任何事情。
  • @mikeo 是的,我搞定了。如果您希望我发布解决方案,请告诉我。

标签: google-app-engine oauth-2.0 identityserver4 claims


【解决方案1】:

可能与我昨天看到的相似。我找到了解决方法here

默认情况下,一些标准声明基本上会映射到 MS 专有密钥。你可以通过这样做来防止这种情况:JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

希望有帮助!

【讨论】:

  • 嗨,有没有办法只删除 sub 声明的规则?
【解决方案2】:

看看 JwtSecurityTokenHandler.InboundClaimTypeMap。它允许您指定来自 JWT 的声明如何映射到 ClaimsIdentity 中的声明。 另一种选择是调查 OIDC 中间件公开的事件,它们可能允许您拦截和操纵从 Google 返回的声明。

【讨论】:

    【解决方案3】:

    或者更具体地说,您还可以使用以下内容

    JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
    

    【讨论】:

      【解决方案4】:

      我在从 google 成功认证时也遇到了类似的问题,我没有收到 sub calim。以下是我的解决方法。

          AddGoogle("Google", o =>
          {
      
               o.ClaimActions.MapUniqueJsonKey("sub", "email");
               o.ClientId = "xxxxxx";
               o.ClientSecret = "zzzzzzzz";
               o.Scope.Clear();
               o.Scope.Add(OidcConstants.StandardScopes.OpenId);
               o.Scope.Add(OidcConstants.StandardScopes.Profile);
               o.Scope.Add(OidcConstants.StandardScopes.Email);
           });
      

      为 ex 映射电子邮件声明。到 ClaimsIdentity 的 sub calim,对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-03
        • 2019-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-04
        • 2013-07-11
        相关资源
        最近更新 更多