【问题标题】:User Info endpoint not finding openid scope用户信息端点未找到 openid 范围
【发布时间】:2018-08-11 21:41:49
【问题描述】:

我正在使用 AuthorizationCode 流将 IdentityServer3 的实施配置为新客户端应用程序(Salesforce 社区)的身份提供者。在客户端点击 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 端点中的某些内容导致检查失败。

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

谢谢!

【问题讨论】:

  • 范围参数的值表示为空格分隔、区分大小写的字符串列表。可能像:"scope": "{ openid }" 或 String[] scopes = new string[] { "openid" };
  • 是的,我可以确认在授权请求期间客户端正在传递“openid”的范围。我尝试添加其他值,例如“openid profile”,但仍然收到关于 openid 检查失败的相同错误。

标签: c# identity openid-connect identityserver3


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    相关资源
    最近更新 更多