Laravel社交名媛-Google身份验证在本地工作,但无法在生产环境中使用:缺少必需的参数代码

时间:2019-11-25 12:05:46

标签: laravel google-authentication laravel-socialite

我的生产环境中出现Laravel Socialite的Google身份验证问题。错误与这篇文章相同:

laravel socialite not working on live server, only works on local machine

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

修改:

客户端错误:POST“ https://www.googleapis.com/oauth2/v4/token”导致“ 400错误请求” 回应:

{
 "error": "invalid_request",
 "error_description": "Missing required parameter: code"
}

2 个答案:

答案 0 :(得分:1)

    public function redirectToProvider($driver)
{
  //  return Socialite::driver($driver)->stateless()->redirect();
    return Socialite::driver('google') ->setScopes(['openid', 'email'])

        ->redirect();
}

答案 1 :(得分:0)

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

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

    vendor \ laravel \ socialite \ src \ Two \ GoogleProvider.php 中删除或评论配置文件范围
{
  "env": {
    "browser": true,
    "node": true,
    "es2021": true
  },
  "plugins": ["vue"],
  "extends": ["eslint:recommended", "plugin:vue/recommended"],
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module"
  },
  "rules": {
   "no-console": "off",
   "no-var": 2,  
   "indent": ["warn", 2],
   "linebreak-style": ["error", "unix"],
   "quotes": ["error", "double"],
   "semi": ["error", "always"]
  }
}
  1. 启动Google OAUth2 stateless();
    protected $scopes = [
        'openid',
        'email',
    ];