Aleksey Dorogov freelance software engineer
← All writing Laravel / PHP

How to fix Undefined variable: access_token Laravel - FacebookProvider

Aug 2025 1 min read Aleksey Dorogov

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 version ~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;

with

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

Sitting on a version of this problem right now? I'd rather look at it than guess.

Email me
Site down? Message me now Live chat · usually reply in minutes