【问题标题】:Google Oauth2 userinfo API not returning user's name dataGoogle Oauth2 userinfo API 不返回用户名数据
【发布时间】:2019-08-27 17:30:06
【问题描述】:

在过去的几个月里,我在使用 OAuth 登录后一直使用这个 URL 来检索用户的姓名和信息。

    https://www.googleapis.com/oauth2/v1/userinfo?alt=json

这给了我以下格式的 JSON:

    {
      "id": "12345",
      "email": "name@gmail.com",
      "verified_email": true,
      "name": "First Last",
      "given_name": "First",
      "family_name": "Last",
      "link": "https://plus.google.com/12345",
      "picture": "https://lh3.googleusercontent.com/123photo.jpg",
      "locale": "en"
    }

今天早上,当我的应用访问此端点时,它得到了以下格式的 JSON:

    {
      "id": "12345",
      "email": "name@gmail.com",
      "verified_email": true,
      "picture": "https://lh3.googleusercontent.com/123/photo.jpg"
    }

我没有对开发者控制台中的配置进行任何更改。有谁知道这个问题的原因可能是什么?

【问题讨论】:

  • Bschweer,你检查过我的答案了吗?它有帮助还是您以其他方式解决了问题?
  • Ján,我可以通过更新范围来解决这个问题。我之前的设置一直运行良好,直到四月初。我确实认为 Google+ 的关闭与我的问题有关。

标签: api oauth-2.0 google-api userinfo


【解决方案1】:

我认为您应该使用不同的 URL - 来自 OpenID Connect 的 URL,它是用于身份验证的 OAuth2 扩展,userinfo 端点在 its RFC 中指定。

https://openidconnect.googleapis.com/v1/userinfo

正确的过程是从OpenID Discovery文档(Google doc)中获取这个URL

https://accounts.google.com/.well-known/openid-configuration

及其userinfo_endpoint 属性。

您一直使用的端点的行为变化可能与 Google+ 被关闭有关。但这只是我的猜测。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-30
    • 1970-01-01
    • 2015-08-13
    • 1970-01-01
    • 1970-01-01
    • 2014-08-27
    相关资源
    最近更新 更多