Google Oauth2 userinfo API not returning user's name data

守給你的承諾、 提交于 2020-01-04 01:51:05

问题


For the past couple months I have been using this url to retrieve a user's name and info after logging in with OAuth.

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

This gave me JSON in the following format:

    {
      "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"
    }

This morning, when my app hit this endpoint, it got JSON in the following format:

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

I have not made any changes to the configuration in the developer console. Does anyone know what the cause of this problem could be?


回答1:


I think you should use a different URL - the one from OpenID Connect, which is an OAuth2 extension for authentication and the userinfo endpoint is specified in its RFC.

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

The correct procedure is to get this URL from the OpenID Discovery document (Google doc)

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

and its userinfo_endpoint attribute.

The change of behavior of the endpoint you have been using may have something to do with Google+ being shut down. But that's just my guess.



来源:https://stackoverflow.com/questions/55541686/google-oauth2-userinfo-api-not-returning-users-name-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!