Laravel Socialite first and last name

laravel socialite google
laravel socialite stateless
laravel socialite api authentication
laravel socialite providers
laravel/socialite facebook
laravel socialite redirect url
laravel passport socialite
laravel socialite tutorial

I'm adding social authentication to an application using Laravel's Socialite. I can retrieve the full name but not the first and last names separately. After the callback happens and Socialite is handling it, the user is retrieved successfully. If I am to dump the user I get back from $user = this->social->driver('facebook')->user(); I get the following:

object(Laravel\Socialite\Two\User)#459 (8) {
     ["token" ]=> string(209) "{token}"
     ["id"] => string(17) "{socialID}"
     ["nickname"] => NULL
     ["name"] => string(14) "{Full Name}"
     ["email"] => string(19) "{Email address}"
     ["avatar"] => string(69) "https://graph.facebook.com/v2.4/{socialID}/picture?type=normal"
     ["user"] => array(6) {
        ["first_name"] => string(6) "{First name}"
        ["last_name"] => string(7) "{Last mame}"
        ["email"] => string(19) "{Email address}"
        ["gender"] => string(4) "male"
        ["verified"] => bool(true)
        ["id"] => string(17) "{socialID}"
    }
    ["avatar_original"] => string(68) "https://graph.facebook.com/v2.4/{socialID}/picture?width=1920"

}

I can obtain the full name or email via $user->name or $user->email however, I can not get the separate first and last names. I have tried $user->first_name as well as trying to dump the $user->user array but all I see is undefined property errors.

I do not want to do something weird like extract it from the full name when the separate first and last name are clearly there as it can get ugly when middle names are present.

I have Googled my way around and weirdly, nobody came across this issue. Am I missing something from the docs? Any suggestions on how to retrieve the first and last name from the user array are greatly appreciated.

According to the dump of the $user var you should be able to access the name values by doing:

$user->user['first_name'] and $user->user['last_name']

Laravel 5.2 - Socialite - First and last name, Hi Everyone ! :) Is there a way with Socialite to get first and last name within Facebook, Twitter, Google plus API ? For the moment, I can only ret Laravel 5.2 - Socialite - First and last name Posted 4 years ago by fdusautoir. Is there a way with Socialite to get first and last name within Facebook, Twitter

I've found that sometimes the user object won't contain the first and last names unless you specify you need those fields.

//get the driver and set desired fields
$driver = Socialite::driver('facebook')
                ->fields([
                    'name', 
                    'first_name', 
                    'last_name', 
                    'email', 
                    'gender', 
                    'verified'
                ]);
// retrieve the user
$user = $driver->user();

then you can get the first name and last name like this

$user->user['first_name'] and $user->user['last_name']

Other stuff you can ask for:

https://developers.facebook.com/docs/graph-api/reference/user/

for google plus:

$user->firstname = $user->user['name']['givenName'];
$user->lastname = $user->user['name']['familyName'];

Laravel Socialite first and last name, Im adding social authentication to an application using Laravels Socialite I can retrieve the full name but not the first and last names Become a Laravel Partner. Laravel Partners are elite shops providing top-notch Laravel development and consulting. Each of our partners can help you craft a beautiful, well-architected project.

You can also use offsetGet() method which is defined in AbstractUser class of socialite package, which returns $this->user[$offset]; so using it you can get first name and last name,

but for facebook and google it differs because of their different response so i have given code below for both facebook and google.

For GOOGLE & FACEBOOK
$providerUser = Socialite::driver($provider)->user(); // $provider can be facebook, google etc.

switch($provider){
   case 'facebook':
      $first_name = $providerUser->offsetGet('first_name');
      $last_name = $providerUser->offsetGet('last_name');
      break;

   case 'google':
      $first_name = $providerUser->offsetGet('given_name');
      $last_name = $providerUser->offsetGet('family_name');
      break;

 // You can also add more provider option e.g. linkedin, twitter etc.

   default:
      $first_name = $providerUser->getName();
      $last_name = $providerUser->getName();
}

$user = User::create([
                'first_name' => $first_name,
                'last_name' => $last_name,
                'email' => $providerUser->getEmail(),
                'image' => $providerUser->getAvatar(),
            ]);

Get first and last name separately from Socialite � Issue #408 , Get first and last name separately from Socialite #408 I think its best to keep it as one column since thats how default laravel does it, then put� To get started with Socialite, use Composer to add the package to your project's dependencies: composer require laravel/socialite "^3.2.0" Configuration. Before using Socialite, you will also need to add credentials for the OAuth services your application utilizes.

In linkedin you can get first and last name from provider like this.

$linkedinUser = $this->socialite->driver('linkedin')->user());

$attributes = [
        'first_name' => $linkedinUser->user['firstName'],
        'last_name' => $linkedinUser->user['lastName'],
        'email' => $linkedinUser->email,
        'avatar' => $linkedinUser->avatar,
        'linkedin_id' => $linkedinUser->id
    ];

Laravel Socialite first and last name, I'm adding social authentication to an application using Laravel's Socialite. I can retrieve the full name but not the first and last names separately. After the� (Last version of Laravel : 5.1 and last version of Socialite : v2.0.11) Please sign in or create an account to participate in this conversation. The most concise screencasts for the working developer, updated daily.

And you could simply do:

$NameArray = explode(' ',$user->getName());
$First_name = $NameArray[0];
$Last_name = $NameArray[1];

Get first name and last name from Facebook, Socialite. Hello, I have not field for name but for first_name and last_name. How can i get first name and last name from Facebook login via socialite? Thanks. Laravel Socialite is a Laravel project/package allowing you to login your users using an external OAuth provider (Like "Sign-in with Google" buttons for instance) My package is an extension to Socialite allowing you to authenticate your users using Telegram. But, you will only have access to first/last name, username, user id, and profile picture.

Laravel Socialite - Laravel, Laravel Socialite. Introduction; Upgrading Socialite; Installation; Configuration; Routing; Optional Parameters; Access Scopes; Stateless Authentication� I'm doing some Android app that needs API and users. I'm planning adding login (and register) button via Facebook. I'm wondering: how should the flow of such an operation look like?

Release Notes - Laravel, First, let's imagine a reusable "alert" component we would like to reuse throughout as the current loop index and whether this is the first or last iteration through the loop: Broadcasting your Laravel events allows you to share the same event names Laravel Socialite is an optional, Laravel 5.0+ compatible package that� composer create-project --prefer-dist laravel/laravel googleLogin. Step 2: Install Socialite. In first step we will install Socialite Package that provide api to connect with google account. So, first open your terminal and run bellow command: composer require laravel/socialite

Auth and first name : laravel, I want to create users that have both a first name and a last name (not just name). for Laravel Socialite, I've also made a SocialiteProviders Telegram provider. A Collection of Providers for Laravel Socialite Documentation. Full documentation for using these providers can be found at the Documentation. Contribute. Submit Pull Requests here for new providers. See the docs for more information.

Comments
  • $user->user['first_name'] should do the trick
  • @koala_dev For some magic reason, the user array was just another undefined property until now. This is silly :) Please add this as an answer so I can mark it as answered. Thanks
  • Note, that the name parts are different with every provider, so with Google eg it's $user->user['name']['givenName'] and $user->user['name']['familyName'].
  • Since different providers provide the first and last name values in different ways, isn't there a consisten way of getting the first and last name as separated values with Socialite? Something like $user->getFirstname and $user->getLastname.
  • This doesn't work with linkedin :/ Do you have any Idea ?
  • Also In google you can get first name as 'givenName' and lastname as 'familyName' in in user object.
  • This does not deal well with names that consist of more than one word, which is not uncommon in last names, but can even be the case in first names (e.g. Gabriel José de la Concordia García Márquez).
  • You should read this: kalzumeus.com/2010/06/17/…