mardi 27 février 2018

Laravel Socialite throws ClientException or InvalidStateException only in production

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



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2FaKe1Z
via IFTTT

Aucun commentaire:

Enregistrer un commentaire