用户信息端点未找到 openid 范围

User Info endpoint not finding openid scope

我正在将我的 IdentityServer3 实现配置为使用 AuthorizationCode 流的新客户端应用程序 (Salesforce Communities) 的身份提供者。一切都按预期工作,直到客户端访问 userinfo 端点,此时发生以下错误:

ERROR IdentityServer3.Core.Validation.TokenValidator Checking for expected scope openid failed

ERROR IdentityServer3.Core.Endpoints.UserInfoEndpointController insufficient_scope

这显然让人相信客户端没有在授权请求中请求 openid 范围,而这在使用 OpenId Connect 时是必需的。但是,我可以确认客户端确实在授权请求中请求了 openid 的范围:

INFO  IdentityServer3.Core.Validation.AuthorizeRequestValidator Authorize request validation success
 {
  "ClientId": "{client_id}",
  "ClientName": "{client_name",
  "RedirectUri": "{redirect_uri}",
  "AllowedRedirectUris": [
    "{allowed_uri_which_matches_request}"
  ],
  "SubjectId": "{subject_id}",
  "ResponseType": "code",
  "ResponseMode": "query",
  "Flow": "AuthorizationCode",
  "RequestedScopes": "openid",
  "State": "{state_value}",
  "SessionId": "402a2356f0bd91a350dfd1f8779ea229",
  "Raw": {
    "response_type": "code",
    "client_id": "{client_id}",
    "redirect_uri": "{redirect_uri}",
    "scope": "openid",
    "state": "{state_value}"
  }
}

我还可以确认 openid 是我的客户端允许的范围,并且 openid 在 ScopeStore 中。

此外,当我查看数据库中生成的令牌时,它们都正确地具有 openid 范围。该 userinfo 端点中的某些内容导致检查失败。

我对这个问题感到非常困惑,因为这个客户端的实现几乎完全是标准的并且开箱即用。如果有帮助,我可以提供所有三个请求的完整日志:授权、令牌和用户信息。

谢谢!

答案最终出现在 DefaultClaimsProvider 的自定义覆盖中,特别是在 GetAccessTokenClaimsAsync 方法中。该方法是手动组合声明列表以添加到令牌,并方便地忽略 openid 的范围声明。我们以前的实现在没有这个声明的情况下是如何工作的,这超出了我的理解范围,但是在将它添加回去之后,一切都很顺利。