1

Observing weird behaviour with the GET request in Laravel 5.7 Facebook Socialite login. Suddenly stopped working and here is what I have found:

  1. At user click login with facebook redirect works correctly, comes back with code get variable in url to my callback function as such:

Request URL:

https://mysite.loc/callback?code=AQD3hC5MTa&state=TvFnYlXwfJsqKm6ZoDbC

Request Method: GET
Status Code: 200 OK

Query String Parameters

code: AQD3hC5MTaJe
state: TvFnYlXwfJsqKm6ZoDbC6I9IaIYWDT4vgvxxx3P4

So far so good, now to the weird stuff debugging in my callback function:

var_dump(\Request::input());

Produces:

array (size=2)
'//callback?code' => string 'AQD3hC5MTaJe' (length=344)
'state' => string 'TvFnYlXwfJsqKm6ZoD' (length=40)

Socialite expects code to be available under

 \Request::input('code')

Which is not in my case it is

\Request::input('//callback?code')

The most bizarre thing I ever seen. I am using NGINX on Docker running Linux. Route:

Route::get('/redirect', 'SocialAuthFacebookController@redirect');
Route::get('/callback', 'SocialAuthFacebookController@callback');

Function signature:

public function callback(SocialFacebookAccountService $service);

UPDATE

Nginx Vhost had:

location / {
    try_files $uri $uri/ /index.php?/$request_uri;
}

Updated to:

try_files $uri $uri/ /index.php?$request_uri;

That made things better, result of debug is now:

array (size=2)
'/callback?code' => string 'AQD3hC5MTaJe' (length=344)
'state' => string 'TvFnYlXwfJsqKm6ZoD' (length=40)

Notice one slash less at front of callback, but it still is truly there... Should just be the code and state variables. Any one can spot what am I doing wrong on the vhost? Looks stock standard...

I am stuck for ideas how to debug the request failure any further, obviously reluctant to change the Socialite code as well. Have tried to access via both query and input - same result...

UPDATE

Answer below is correct. Editing Nginx Vhost to reflect fixed the issue:

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

Incredibly any tutorial found online for setting up Nginx with Laravel has the wrong setting. Good to collect this info here.

Vlad
  • 131
  • 2
  • 8

1 Answers1

2

this is an issue with the redirection of the request to public/index.php of laravel.

it's either in the vhost declaration of nginx or in your .htaccess

basicly, it's getting https://mysite.loc/callback?code=AQD3hC5MTa&state=TvFnYlXwfJsqKm6ZoDbC

redirect it to

https://mysite.loc/index.php?//callback?code=AQD3hC5MTa&state=TvFnYlXwfJsqKm6ZoDbC

instead of

https://mysite.loc/index.php/callback?code=AQD3hC5MTa&state=TvFnYlXwfJsqKm6ZoDbC

ps: the using of the domain name and protocol in the redirection example https://mysite.loc/ is just for clarification. nginx doest do that exactly

Update: Here is what i'm putting in my nginx vhost

/index.php$is_args$args
N69S
  • 16,110
  • 3
  • 22
  • 36
  • Thank you N69S, giving an up vote! Spot on! Only issue is 1 forward slash still remains after vhost clean up - updated my question with clean up details! – Vlad Oct 24 '18 at 22:40
  • @Vlad added an example in my answer – N69S Oct 25 '18 at 13:33