Laravel Socialite with Google saves different ID number, causes duplicate error
I got Laravel 5.2 and the latest version of Socialite to work properly with Twitter and Facebook login, but not with Google Login.
With Google, the user can log in the first time and get inserted into the database. However, when the user re-atttempts to log in after a log out, there is a problem. In my callback function, the getId() call is returning a number such as 1048710206853583#####. However, in the MySQL database, a number such as 92233720368547##### is getting stored after the user's first login in a provider_id field. This is happening with one single getId() call that I'm using. It appears that Google is returning two different Ids. Could this be? What could I be doing wrong?
public function redirectToProvider($provider = null)
{
if(!config("services.$provider")) abort('404'); //handle providers that don't exist
return Socialite::driver($provider)->redirect();
}
public function handleProviderCallback($provider = null)
{
$social_user = Socialite::driver($provider)->user();
$oauth_id = $social_user->getId();
$user = User::where('oauth_id', $oauth_id)->first();
if (!$user) {
$user = new User();
$user->email = $social_user->getEmail();
if($social_user->getNickname() && strlen( $social_user->getNickname() ) > 0)
$user->username = $social_user->getNickname();
else
$user->username = $social_user->getEmail();
$user->oauth_id = $oauth_id;
$user->oauth_type = $provider;
$user->password = null;
$user->confirmation_code = null;
$user->save();
}
Auth::loginUsingId($user->id);
...
}
链接地址: http://www.djcxy.com/p/33118.html
上一篇: Laravel Socialite:AbstractProvider.php中的InvalidStateException行199: