Google Oauth2 userinfo API未返回用户名数据 [英] Google Oauth2 userinfo API not returning user's name data

查看:238
本文介绍了Google Oauth2 userinfo API未返回用户名数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几个月中,我在使用OAuth登录后一直使用此网址来检索用户的名称和信息.

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

这给了我以下格式的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"
    }

今天早晨,当我的应用程序到达此端点时,它以以下格式获取了JSON:

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?

推荐答案

我认为您应该使用不同的URL-来自OpenID Connect的URL,它是用于身份验证的OAuth2扩展,在中指定了userinfo终结点href ="https://openid.net/specs/openid-connect-core-1_0.html#UserInfo" rel ="nofollow noreferrer">其RFC .

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

正确的步骤是从 OpenID发现文档( Google文档)

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

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

及其userinfo_endpoint属性.

您一直在使用的端点的行为更改可能与Google+被关闭有关.但这只是我的猜测.

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.

这篇关于Google Oauth2 userinfo API未返回用户名数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆