Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
FacebookProvider for Socialite October 2020
Author: Gkiokan Sali
Date: 2020-10-23
Comment: This is a working updated Facebook Provider for the Laraval Package Socialite.
It inherits the new changes on the User Image Endpoint and returns the new full User Image path
according to the new specs of fb with an access_token.
namespace Gkiokan\Auth\Http\Controllers\Socialite;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
// use Gkiokan\Auth\Models\User;
use Laravel\Socialite\Two\FacebookProvider as Provider;
use Laravel\Socialite\Two\User;
use Http;
use Arr;
class FacebookProvider extends Provider
protected $version = 'v8.0';
protected $fields = ['name', 'email', 'gender', 'verified', 'link', 'picture'];
protected function mapUserToObject(array $user)
// latest orginal
// $avatarUrl = $this->graphUrl.'/'.$this->version.'/'.$user['id'].'/picture';
$avatarUrl = $this->getFacebookAvatar($user);
return (new User)->setRaw($user)->map([
'id' => $user['id'],
'nickname' => null,
'name' => $user['name'] ?? null,
'email' => $user['email'] ?? null,
'avatar' => $avatarUrl, // .'?type=normal&access_token=' . $access_token,
'avatar_original' => $avatarUrl, // .'?width=1920&accss_token=' . $access_token,
'profileUrl' => $user['link'] ?? null,
public function getAccessToken(){
$res = Http::get("", [
"client_id" => config('services.facebook.client_id'),
"client_secret" => config('services.facebook.client_secret'),
"grant_type" => "client_credentials",
$r = $res->json();
return Arr::get($r, 'access_token', false);
public function getFacebookAvatar(array $user){
$access_token = $this->getAccessToken();
$path = $this->graphUrl.'/'.$this->version.'/'.$user['id'].'/picture?type=large&redirect=false&access_token=' . $access_token;
$res = Http::get($path);
return Arr::get($res->json(), 'data.url', false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment