【发布时间】:2021-12-03 14:23:05
【问题描述】:
我正在尝试实现新的“使用 Google 登录”按钮,如 https://developers.google.com/identity/gsi/web/guides/display-button 中所述。
一切都很好,我可以从带有“credential”和“g_csrf_token”元素的按钮获得响应,我可以将其发送到我的服务器。但是,使用 Google API 客户端解码凭据不起作用。我正在尝试关注instructions。
这是我的代码:
$id_token = filter_input(INPUT_POST, 'credential');
$csrfToken = filter_input(INPUT_POST, 'g_csrf_token'); //??? Do we need this?
$client = new Google_Client(['client_id' => $clientid]);
$client->addScope("email"); // Recommended in another StackOverflow answer but makes no difference
try {
$payload = $client->verifyIdToken($id_token);
} catch(Exception $ex) {
$errorMessage = "Error in verifyIdToken():" . $ex->getMessage();
// ...do stuff with the error message
}
// ...do stuff with the returned payload
结果是错误消息id_token must be passed in or set as part of setAccessToken。
我已将我的 Google API 客户端更新到 v2.11。
我假设我在某个地方错过了一步 - 有人可以帮忙吗?
【问题讨论】:
标签: php jwt google-signin google-identity