Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Socialite 2.0 Facebook Authentication only returning id and name

I am using Laravel's Socialite package (version 2.0.0). It is working great for google and github but when I try to login with facebook, I get this:

ErrorException in FacebookProvider.php line 89:
Undefined index: first_name

In the FacebookProvider.php the error is from this method:

protected function mapUserToObject(array $user)
{
    return (new User)->setRaw($user)->map([
        'id' => $user['id'], 'nickname' => null, 'name' => $user['first_name'].' '.$user['last_name'],
        'email' => isset($user['email']) ? $user['email'] : null, 'avatar' => $this->graphUrl.'/'.$this->version.'/'.$user['id'].'/picture?type=normal',
    ]);
}

If I dd() the $user param before this mapping. I only get id and the name of the authenticated Facebook user. So, it means that I am not getting the email of the Facebook user. I at least need name and email of the user.

After dd() this method looks like this:

protected function mapUserToObject(array $user)
{
    dd($user);
    return (new User)->setRaw($user)->map([
        'id' => $user['id'], 'nickname' => null, 'name' => $user['first_name'].' '.$user['last_name'],
        'email' => isset($user['email']) ? $user['email'] : null, 'avatar' => $this->graphUrl.'/'.$this->version.'/'.$user['id'].'/picture?type=normal',
    ]);
}

What could be the problem? Please help me.

like image 623
Homo Sapien Avatar asked Mar 15 '23 10:03

Homo Sapien


1 Answers

I have the same problem and is a bug! use the new version of file FacebookProvider.php here and work!

like image 174
German Avatar answered Mar 24 '23 21:03

German