doucitao2944 2018-02-27 14:31
浏览 165

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

I have for the last 8 hours tried to fix a login problem with Laravel Socialite that only accurs when i'm on production server (Ubuntu 16 and LEMP stack). The login with Socialite works on localhost. I'm using Laravel 5.5 and Socialite 3.0.

The problem is when Facebook redirects back with the code and state params and Socialite tries to get the token. The url below gives the 500 error..

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

Controller:

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);

}

Using the handler with Socialite::driver($provider)->user(); throws..

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

When I change the handler to Socialite::driver($provider)->stateless()->user(); it throws

(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)
...

It feels like I have tried everything from the forums like SERVICE_DOMAIN in services.php, ngix settings, stateless(), clear cache, doublecheck facebook panel setting, .env file etc but it won't work..

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab实现基于主成分变换的图像融合。
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊