Google OAuth 2 重定向 URI 不匹配

问题描述 投票:0回答:2

我已经在使用谷歌应用程序进行身份验证。现在,我已将其他 URL 添加到“授权重定向 URI”,但这些 URL 不起作用。旧的可以正常工作,但是当我使用新的 URL 时,谷歌返回以下错误而不是谷歌身份验证令牌。

{"error":"redirect_uri_mismatch","error_description":"Bad Request"}

请建议我解决方案。

这是我生成登录网址的代码:

require_once "../vendor/autoload.php";
$gClient = new Google_Client();
$gClient->setClientId("clientID");
$gClient->setClientSecret("clientSECRET");
$gClient->setApplicationName("MY GOOGLE APP");
$gClient->setRedirectUri("https://example.com/TEST/authenticate/pages_authnicate_google.php");
$gClient->addScope("https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/spreadsheets");
$gClient->setAccessType("offline"); 
$gClient->setPrompt('consent');
$loginURL = $gClient->createAuthUrl();
php google-oauth google-sheets-api google-api-php-client
2个回答
0
投票

仔细检查您之前在授权请求中发送的内容是否与您在请求中发送到令牌端点的内容匹配。您可以使用在 API 控制台中配置的任一 URL,但两个请求中的 URL 必须相同。

确保redirect_uri:'https://www.example.org/token'与Google客户端API上的'授权重定向URI'块配置相同。

就我而言,它有效......!!!


0
投票

我遇到了同样的问题,发现可用的答案不完整。将正确的 URI 添加到授权的 URI 中还不够。因为您使用此

$client->setAuthConfig()
包含了 AuthConfig 文件, 这些授权的 URI 列在该 JSON 配置文件中。添加授权 URI 后,重新下载该配置文件。

© www.soinside.com 2019 - 2024. All rights reserved.