Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oauth 2.0 Google oauth2不返回id\u令牌_Oauth 2.0_Google Oauth - Fatal编程技术网

Oauth 2.0 Google oauth2不返回id\u令牌

Oauth 2.0 Google oauth2不返回id\u令牌,oauth-2.0,google-oauth,Oauth 2.0,Google Oauth,我似乎错过了oauth2的一些东西。我获得了access\u令牌,但没有id\u令牌 我使用以下方法通过传递从https://accounts.google.com/o/oauth2/auth $oauth2token_url = "https://accounts.google.com/o/oauth2/token"; $clienttoken_post = array( "code" => $code, "client_id" => $client_id,

我似乎错过了oauth2的一些东西。我获得了
access\u令牌
,但没有
id\u令牌

我使用以下方法通过传递从
https://accounts.google.com/o/oauth2/auth

$oauth2token_url = "https://accounts.google.com/o/oauth2/token";
$clienttoken_post = array(
    "code" => $code,
    "client_id" => $client_id,
    "client_secret" => $client_secret,
    "redirect_uri" => $redirect_uri,
    "grant_type" => "authorization_code"
);

$curl = curl_init($oauth2token_url);

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$json_response = curl_exec($curl);
curl_close($curl);
var_dump($json_response);
一切似乎都正常,但根据谷歌的文档,我应该得到
access\u token,id\u token,expires\u in,token\u type
,除了
id\u token

var\u dump($json\u响应)显示以下内容:

string(126) "{ "access_token" : "ya29.AHES6ZSGlHVW9qA23xs8bHBP578Ef8S5cntJIcPT_SHWA", "token_type" : "Bearer", "expires_in" : 3598 }

这里我遗漏了什么?

在令牌端点,只有在存在某些作用域的情况下才会发出id\u令牌,文档应该对此进行澄清


仅当使用了电子邮件、配置文件或OpenID连接作用域时,才会发出此消息。id\u标记在其他情况下没有意义。

首先,您需要为响应类型添加id\u标记。 然后你需要检查范围。 不要忘记,对于隐式流,nonceparam是必需的

有关更多信息和示例,您可以查看:

非常感谢,伙计。我已经在这里拉扯了好几天的头发,想弄清楚如何得到一个身份证代币。我将包括电子邮件范围,并希望它能起到作用。@Kal接受并投票给我答案将不胜感激。你救了我的命!非常感谢。从2021年3月30日起,
scopes=[“openid”https://www.googleapis.com/auth/userinfo.email“,]”
成功了。