我使用laravel 5.6和laravel / socialite:“ ^ 3.2.0”通过Facebook进行身份验证,但是登录到Facebook用户电子邮件为空(用户Facebook帐户具有电子邮件)
我的身份验证代码:
public function redirectToProvider($provider)
{
return Socialite::driver($provider)->redirect();
}
public function handleProviderCallback($provider)
{
$user = Socialite::driver($provider)->user();
dd($user);
$authUser = $this->findOrCreateUser($user, $provider);
Auth::login($authUser, true);
return redirect($this->redirectTo);
}
public function findOrCreateUser($user, $provider)
{
$authUser = User::where('provider_id', $user->id)->first();
if ($authUser) {
return $authUser;
}
return User::create([
'name' => $user->name,
'email' => $user->email,
'provider' => $provider,
'provider_id' => $user->id
]);
}
[1]: https://i.stack.imgur.com/6zYEI.png
答案 0 :(得分:1)