oauth-2.0 - Google oauth2 不返回 id_token

标签 oauth-2.0 google-oauth

我似乎错过了 oauth2 的一些东西。我得到 access_token 但没有 id_token !

我使用以下内容通过传递 https://accounts.google.com/o/oauth2/auth 授予我的“代码”来获得 google access_token

$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);

一切似乎都有效,但根据谷歌的文档 https://developers.google.com/accounts/docs/OAuth2Login#exchangecode 我应该得到 access_token, id_token, expires_in, token_type,除了 id_tokenvar_dump($json_response); 显示以下内容:
string(126) "{ "access_token" : "ya29.AHES6ZSGlHVW9qA23xs8bHBP578Ef8S5cntJIcPT_SHWA", "token_type" : "Bearer", "expires_in" : 3598 }

我在这里缺少什么?

最佳答案

在 token 端点,仅当存在某些范围时才会发出 id_token,文档应阐明这一点。

仅当使用电子邮件、配置文件或 OpenID Connect 范围时才会发出它。否则 id_token 没有意义。

关于oauth-2.0 - Google oauth2 不返回 id_token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18123018/

相关文章:

facebook-graph-api - Grails Spring Security如何在自定义身份验证中记住Me?

oauth - 在 Google API 中检测已撤销的 App 权限

php - OAuth 2.0 服务器 PHP,找不到接口(interface)

java - 从 google OAuth 登录后刷新页面不起作用

google-drive-api - 拒绝在框架中显示,因为它将 'X-Frame-Options' 设置为 'SAMEORIGIN'

java - 无法找到 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' 类型的 Bean。 - Spring 安全

electron - Electron 应用程序上的google身份验证

oauth-2.0 - 使用 OAuth2 将 JHipster 中的前端和 API 服务器分开不起作用

android - 如何重定向回 Android 应用程序?

c# - 使用 ScriptService 时为 "Google.GoogleApiException: Google.Apis.Requests.RequestError Request is missing required authentication credential"