我无法使用 Laravel 10 和 Socialite 添加多个 Google 帐户

问题描述 投票:0回答:1

我尝试使用 Laravel 10 和 Socialite 创建多个 Google 服务;

在 Services.php 中我添加:

'sign_in_google' => [
    'client_id' => env('SIGN_IN_GOOGLE_ID'),
    'client_secret' => env('SIGN_IN_GOOGLE_SECRET'),
    'redirect' => 'http://localhost:8000/sign-in/google/callback'
],
'sign_up_google' => [
    'client_id' => env('SIGN_UP_GOOGLE_ID'),
    'client_secret' => env('SIGN_UP_GOOGLE_SECRET'),
    'redirect' => 'http://localhost:8000/sign-up/google/callback'
]

当我尝试通过控制器使用它时:

public function signInRedirect() {
    return Socialite::driver('sign_in_google') -> redirect();
}

显示错误:

Driver [user_sign_in_google] not supported.
laravel laravel-socialite
1个回答
0
投票

因为您使用的是 Socialite 不支持的自定义驱动程序名称,所以您不能使用 driver 方法。

您需要使用buildProvider方法,如下所示:

use Laravel\Socialite\Two\GoogleProvider;

public function signInRedirect()
{
    $driver = Socialite::buildProvider(
        GoogleProvider::class, config('services.sign_in_google')
    );

    return $driver->redirect();
}
© www.soinside.com 2019 - 2024. All rights reserved.