Added google select_account test

Also cleaned the function naming a little to be more descriptive of the
work they do.
This commit is contained in:
Dan Brown 2018-11-10 14:52:43 +00:00
parent 4be0c567cc
commit 178b5af83a
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
3 changed files with 19 additions and 8 deletions

View File

@ -40,7 +40,7 @@ class SocialAuthService
public function startLogIn($socialDriver) public function startLogIn($socialDriver)
{ {
$driver = $this->validateDriver($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) public function startRegister($socialDriver)
{ {
$driver = $this->validateDriver($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 * 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')) $driver = $this->socialite->driver($driverName);
{
return $this->socialite->driver($driver)->with(['prompt' => 'select_account']); if ($driverName === 'google' && config('services.google.select_account')) {
$driver->with(['prompt' => 'select_account']);
} }
return $this->socialite->driver($driver); return $driver;
} }
} }

View File

@ -41,6 +41,7 @@
<env name="GOOGLE_APP_SECRET" value="aaaaaaaaaaaaaa"/> <env name="GOOGLE_APP_SECRET" value="aaaaaaaaaaaaaa"/>
<env name="GOOGLE_AUTO_REGISTER" value=""/> <env name="GOOGLE_AUTO_REGISTER" value=""/>
<env name="GOOGLE_AUTO_CONFIRM_EMAIL" value=""/> <env name="GOOGLE_AUTO_CONFIRM_EMAIL" value=""/>
<env name="GOOGLE_SELECT_ACCOUNT" value=""/>
<env name="APP_URL" value="http://bookstack.dev"/> <env name="APP_URL" value="http://bookstack.dev"/>
<env name="DEBUGBAR_ENABLED" value="false"/> <env name="DEBUGBAR_ENABLED" value="false"/>
</php> </php>

View File

@ -148,4 +148,12 @@ class SocialAuthTest extends TestCase
$this->assertDatabaseHas('social_accounts', ['user_id' => $user->id]); $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'));
}
} }