Laravel Socialite仅在生产中抛出ClientException或InvalidStateException

时间:2018-02-27 14:31:43

标签: php laravel laravel-5 laravel-socialite

我在过去的8个小时里试图解决Laravel Socialite的登录问题,当我在生产服务器(Ubuntu 16和LEMP堆栈)时,只有诅咒。使用Socialite登录适用于localhost。我正在使用Laravel 5.5和Socialite 3.0。

问题是当Facebook重定向代码和状态参数并且Socialite尝试获取令牌时。下面的网址给出了500错误..

https://website.com/auth/facebook/callback?code=AQA-KiBJG3Ge_3DqktPGjpjrqIbmOy2Q4f6nW...&state=V9uOnjYU6cOHu0rbs...

控制器:

public function redirectToProvider($provider)
{

    return Socialite::driver($provider)->scopes(['user_birthday', 'user_work_history', 'user_education_history'])->redirect();
}

public function handleProviderCallback($provider)
{

    $user = Socialite::driver($provider)->user(); //Where error is thrown

    session()->put('fb_token', $user->token);

}

使用Socialite::driver($provider)->user();处理程序抛出..

    (1/1) InvalidStateException
    in AbstractProvider.php (line 209)
    at AbstractProvider->user()
    in LoginController.php (line 65)
    at LoginController->handleProviderCallback('facebook')
    ...

当我将处理程序更改为Socialite::driver($provider)->stateless()->user();时,它会抛出

(1/1) ClientException
Client error: `POST https://graph.facebook.com/v2.10/oauth/access_token` resulted in a `400 Bad Request` response:
{"error":{"message":"Missing authorization code","type":"OAuthException","code":1,"fbtrace_id":"hghkl145"}}
in RequestException.php (line 113)
at RequestException::create(object(Request), object(Response))
in Middleware.php (line 65)
at Middleware::GuzzleHttp\{closure}(object(Response))
in Promise.php (line 203)
at Promise::callHandler(1, object(Response), array(object(Promise), object(Closure), null))
in Promise.php (line 156)
...

感觉就像我在services.php,ngix设置,无状态(),清除缓存,双重检查facebook面板设置,.env文件等的论坛中尝试了所有内容,但它无法正常工作..

0 个答案:

没有答案