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 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题