Observing weird behaviour with the GET request in Laravel 5.7 Facebook Socialite login. Suddenly stopped working and here is what I have found:
- 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.