Laravel 社交名流 - Google 身份验证在本地工作但不在生产中工作:缺少必需的参数代码

Vau*_*unt 5 google-authentication laravel laravel-socialite

我在生产环境中使用 Laravel Socialite 的 Google 身份验证时遇到问题。错误与此帖子中的错误相同:

Laravel Socialite 无法在实时服务器上运行,只能在本地计算机上运行

但我有一个 Apache 服务器,经过多次尝试,我还没有找到解决方案。

编辑:

客户端错误:POST“ https://www.googleapis.com/oauth2/v4/token ”导致“400 Bad Request”响应:

{
 "error": "invalid_request",
 "error_description": "Missing required parameter: code"
}
Run Code Online (Sandbox Code Playgroud)

小智 -2

此问题是由于vendor\laravel\socialite\src\Two\GoogleProvider.php中的配置文件范围而发生的。

您可以通过以下两种方法克服此错误:

  1. 删除或评论供应商\laravel\socialite\src\Two\GoogleProvider.php中的配置文件范围
    protected $scopes = [
        'openid',
        'email',
    ];
Run Code Online (Sandbox Code Playgroud)
  1. 启动Google OAUth2 stateless();
    return Socialite::driver('google')->stateless()->redirect();
Run Code Online (Sandbox Code Playgroud)