independent full stack developer

/ Developer's blog

How to fix Undefined variable: access_token Laravel - FacebookProvider

Sunday, August 07, 2022

Today when I try to sign in via Facebook to my Laravel project, I got an error 

Undefined variable: access_token vendor/laravel/socialite/src/Two/FacebookProvider.php

If you use fersion ~1.0

To make it work normally with hotfix, open vendor/laravel/socialite/src/Two/FacebookProvider.php and replace

parse_str($body, $data);
return $access_token;


parse_str($body, $data);
$json = json_decode(key($data));
return $json->access_token;

For version 3

parse_str($response->getBody(), $data);
$json = json_decode(key($data), true);
return Arr::add($json, 'expires_in', Arr::pull($json, 'expires'));

Issue opened on github

7059 people already saw it