mercredi 25 mai 2016

Laravel Socialite - What are the available fields from Google API

I am able to successfully setup Socialite on my Laravel app and authenticate using GitHub, but not for Google. Below I show my routes, and also the findOrCreateUser function inside my AuthController.php file, which all works fine using GitHub:

Routes

Route::get('auth/{provider}', 'Auth\AuthController@providerRedirect');
Route::get('auth/{provider}/callback', 'Auth\AuthController@providerCallback');

AuthController

private function findOrCreateUser($providerUser)
{
    if ($authUser = User::where('provider_id', $providerUser->id)->first()) {
        return $authUser;
    }

    return User::create([
        'name' => $providerUser->name,
        'username' => $providerUser->nickname,
        'email' => $providerUser->email,
        'avatar' => $providerUser->avatar,
        'provider_id' => $providerUser->id
    ]);
}

The problem I am experiencing is Google does not seem to be detecting 'username' => $providerUser->nickname, so I receive the error Integrity constraint violation: 1048 Column 'username' cannot be null, because I am not inserting anything for username. I would like to capture both the user's username and their real name from Google. With GitHub I am able to detect these using this method. How can see what fields are available to me from Google?

I will gladly post more code if that would help.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/22pf611
via IFTTT

Aucun commentaire:

Enregistrer un commentaire