在Laravel中使用Socialite进行身份验证时出现cURL错误6

时间:2020-05-01 08:59:45

标签: php laravel curl laravel-socialite

我在Laravel中使用Socialite软件包进行身份验证。我已经将应用程序上传到主机了很长时间,并且auth总是成功。但最近,它遇到了一些cURL错误,基本上说GuzzleHttp \ Exception \ ConnectException cURL error 6: getaddrinfo() thread failed to start (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)。我不知道为什么会这样。我读过一些文章,没有什么能解决我的问题。有谁知道如何解决这个问题?谢谢。

这是我的代码

<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;
class AuthController extends Controller
{
    public function redirectToProvider($provider)
    {
        return Socialite::driver($provider)->redirect();
    }
    /**
     * Obtain the user information from provider.  Check if the user already exists in our
     * database by looking up their provider_id in the database.
     * If the user exists, log them in. Otherwise, create a new user then log them in. After that
     * redirect them to the authenticated users homepage.
     *
     * @return Response
     */
    public function handleProviderCallback($provider)
    {
        $user = Socialite::driver($provider)->user();
        $authUser = $this->findOrCreateUser($user, $provider);
        Auth::login($authUser, true);
        return redirect('/');
    }
    /**
     * If a user has registered before using social auth, return the user
     * else, create a new user object.
     * @param  $user Socialite user object
     * @param $provider Social auth provider
     * @return  User
     */
    public function findOrCreateUser($user, $provider)
    {
        $authUser = User::where('provider_id', $user->id)->first();
        if ($authUser) {
            return $authUser;
        }
        else{
            $data = User::create([
                'name'     => $user->name,
                'email'    => !empty($user->email)? $user->email : '' ,
                'provider' => $provider,
                'provider_id' => $user->id
            ]);
            return $data;
        }
    }
}

0 个答案:

没有答案
相关问题