laravel socialite在实时服务器上不起作用,仅在本地计算机上工作 [英] laravel socialite not working on live server, only works on local machine

查看:92
本文介绍了laravel socialite在实时服务器上不起作用,仅在本地计算机上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的应用程序移到了实时服务器中.
问题是laravel社交名流停止了工作,以下是说明:
我单击Google登录名,然后选择电子邮件,然后在回调中发生这种情况:
InvalidStateException on Abstract.php on line 200.
要解决此问题,我使用了stateless(),现在新的错误是:
Client error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `400 Bad Request` response: { "error": "invalid_request", "error_description": "Missing required parameter: code" }

I have recently moved my application into a live server.
The problem is laravel socialite stopped working, below is the explanation:
I click on google login and after choosing email, on callback this happens:
InvalidStateException on Abstract.php on line 200.
To fixed this issue i used stateless() and now the new error is :
Client error: `POST https://www.googleapis.com/oauth2/v4/token` resulted in a `400 Bad Request` response: { "error": "invalid_request", "error_description": "Missing required parameter: code" }

以下是我已经尝试过的事情清单:
1-在Google网站中,我将google api urlcallback url更新为新的实时域名地址: http://www.domain-name.comhttp://www.domain-name.com/login/google/callback

Here is the list of things i have already tried:
1- In Google website, I updated google api url and callback url to new live domain addresses: http://www.domain-name.com and http://www.domain-name.com/login/google/callback

2-我修改了config/session.php文件,如下所示:
'domain' => env('SESSION_DOMAIN', 'www.domain-name.com'),

2- I have modified config/session.php file like this:
'domain' => env('SESSION_DOMAIN', 'www.domain-name.com'),

3-我的存储文件夹已经具有这样的权限:
drwxrwxr-x 5 root www-data 4096 Jun 24 18:30 storage

3- My storage folder is already have permission like this:
drwxrwxr-x 5 root www-data 4096 Jun 24 18:30 storage

4-我更改了vendor\laravel\socialite\src\Two\GoogleProvider.php文件并删除了配置文件",现在看起来像这样:

4- I changed vendor\laravel\socialite\src\Two\GoogleProvider.php file and removed 'profile' and now it looks like this:

protected $scopes = [
'openid',
'email',
];

5-我使用了php artisan cache:clearcomposer dump-autoload,并多次清除了浏览器缓存数据.

5- I used php artisan cache:clear , composer dump-autoload, and cleared browser cache data many times.

6-我尝试使用$userSocial = Socialite::with('google')->user();而不是$userSocial = Socialite::driver('google')->user();,但我仍然得到InvalidStateException on Abstract.php on line 200.仅当我更改为$userSocial = Socialite::driver('google')->stateless()->user();时,错误才会更改为我在问题开始时所说的内容.

6- I tried $userSocial = Socialite::with('google')->user(); instead of $userSocial = Socialite::driver('google')->user(); , and i still get InvalidStateException on Abstract.php on line 200. only when i change to $userSocial = Socialite::driver('google')->stateless()->user(); the error changes to what i said at the beginning of the question.

我的config/services.php文件是这样的:

'google' => [
    'client_id' => 'my-correct-client-id-from-google',
    'client_secret' => 'my-correct-client-secret-from-google',
    'redirect' => 'http://www.domain-name.com/login/google/callback',
],

我已经尝试修复此问题2天了.任何帮助将不胜感激.

I have been trying to fix this for 2 days now. any help would be appreciated.

推荐答案

浪费了许多小时.终于找到了答案:
那是nginx:
所以我跑了sudo nano /etc/nginx/sites-available/default

after many hours wasted. finally found the answer:
it was nginx:
so i ran sudo nano /etc/nginx/sites-available/default

并修复此行:

try_files $uri $uri/ /index.php?query_string; // wrong 

try_files $uri $uri/ /index.php?$query_string; // fixed 

这篇关于laravel socialite在实时服务器上不起作用,仅在本地计算机上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆