gpt4 book ai didi

php - 使用 Google ID token 和 Laravel Socialite 授权 native 应用程序用户提供 401

转载 作者:行者123 更新时间:2023-12-04 04:10:56 36 4
gpt4 key购买 nike

我在通过 Google 进行 Socialite 身份验证时遇到问题。我有两个独立的应用程序:Laravel 和 React Native。对于 native 应用程序,我使用 @react-native-community/google-signin 并在客户端上获取 token 后将其发送到 Laravel 应用程序,在那里我将此 token 传递给 Socialite 函数: Socialite::driver('google ')->userFromToken($token); .我收到此错误:

Client error: GET https://www.googleapis.com/oauth2/v3/userinfo?prettyPrint=false resulted in a 401 Unauthorized response:
{
"error": "invalid_request",
"error_description": "Invalid Credentials"
}

我已重新检查凭据 4 次,我确信它们是正确的。我使用与 native 应用程序相同的客户端 ID。我究竟做错了什么?

注意:我使用 ID token 而不是 auth token 进行授权。

最佳答案

根据我对类似问题的研究 - 看起来 Google 一键式的工作方式与 oAuth 的工作方式不同。
因此,您必须从 $token 中获取用户。手动,使用 google/apiclient包裹。
谷歌文档中有一个例子(它在 android 部分,但这些特定的片段指的是后端部分,所以它仍然应该可以解决问题)composer require google/apiclient


// Get $id_token via HTTPS POST.

$client = new Google_Client(['client_id' => $CLIENT_ID]); // Specify the CLIENT_ID of the app that accesses the backend
$payload = $client->verifyIdToken($id_token);
if ($payload) {
$userid = $payload['sub'];
// If request specified a G Suite domain:
//$domain = $payload['hd'];
} else {
// Invalid ID token
}
您可以在此找到更多信息 Google Docs Page

关于php - 使用 Google ID token 和 Laravel Socialite 授权 native 应用程序用户提供 401,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61748355/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com