diff --git a/app/Auth/Access/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php index 66f567c98..0d46b9f88 100644 --- a/app/Auth/Access/SocialAuthService.php +++ b/app/Auth/Access/SocialAuthService.php @@ -40,7 +40,7 @@ class SocialAuthService public function startLogIn($socialDriver) { $driver = $this->validateDriver($socialDriver); - return $this->redirectToSocialProvider($driver)->redirect(); + return $this->getSocialDriver($driver)->redirect(); } /** @@ -52,7 +52,7 @@ class SocialAuthService public function startRegister($socialDriver) { $driver = $this->validateDriver($socialDriver); - return $this->redirectToSocialProvider($driver)->redirect(); + return $this->getSocialDriver($driver)->redirect(); } /** @@ -250,15 +250,17 @@ class SocialAuthService /** * Provide redirect options per service for the Laravel Socialite driver - * @param $driver + * @param $driverName + * @return \Laravel\Socialite\Contracts\Provider */ - public function redirectToSocialProvider($driver) + public function getSocialDriver(string $driverName) { - if ($driver == 'google' && config('services.google.select_account')) - { - return $this->socialite->driver($driver)->with(['prompt' => 'select_account']); + $driver = $this->socialite->driver($driverName); + + if ($driverName === 'google' && config('services.google.select_account')) { + $driver->with(['prompt' => 'select_account']); } - return $this->socialite->driver($driver); + return $driver; } } diff --git a/phpunit.xml b/phpunit.xml index efed0070e..3d18d9bbf 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -41,6 +41,7 @@ + diff --git a/tests/Auth/SocialAuthTest.php b/tests/Auth/SocialAuthTest.php index 572c32f46..b8ca81174 100644 --- a/tests/Auth/SocialAuthTest.php +++ b/tests/Auth/SocialAuthTest.php @@ -148,4 +148,12 @@ class SocialAuthTest extends TestCase $this->assertDatabaseHas('social_accounts', ['user_id' => $user->id]); } + public function test_google_select_account_option_changes_redirect_url() + { + config()->set('services.google.select_account', 'true'); + + $resp = $this->get('/login/service/google'); + $this->assertContains('prompt=select_account', $resp->headers->get('Location')); + } + }