我试图使用Laravel Socialite版本9,我在使用Laravel Socialite与谷歌帐户时遇到错误,但在本地它工作得很好,这里是错误消息:"cURL error 6: getaddrinfo() thread failed to start (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://www.googleapis.com/oauth2/v4/token"
下面是代码:
public function redirectToGoogle()
{
// $error = 'dafasdfasdfas';
// return redirect()->route('backpack.auth.login')->with('error','Not allow ');
return Socialite::driver('google')->redirect();
}
/**
* Create a new controller instance.
*
* @return void
*/
public function handleGoogleCallback()
{ // Try to exception
try {
$user = Socialite::driver('google')->user(); // google gmail
if (explode("@", $user->email)[1] != 'global-mobility-service.com'){
return redirect()->route('backpack.auth.login')->with('error','Email Not Allow');
}
$finduser = User::where('email', '=', $user->email)->first();
if(isset($finduser) == true){
$updateUser = User::where('email', '=', $user->email)->update([
'email' => $user->email,
'google_id'=> $user->id,
]);
Auth::login($finduser);
return redirect()->intended('admin/dashboard');
}else{
$newUser = User::create([
'name' => $user->name,
'email' => $user->email,
'google_id'=> $user->id,
'password' => encrypt('123456')
]);
$newUser->assignRole(2);
Auth::login($newUser);
return redirect()->intended('admin/dashboard');
}
} catch (Exception $e) {
dd($e->getMessage());
}
}
感谢你们的帮助。谢谢
1条答案
按热度按时间0lvr5msh1#
但在当地效果很好
基于此,我假设你正在部署你的代码 * 某处 *,这就是你遇到这个问题的地方。因此,我认为您需要检查是否可以从部署代码的位置访问https://www.googleapis.com。检查任何可能阻止外线呼叫的防火墙或网络设置。
希望这有帮助!