From a76599bd2aaf85040b67b3ce2f64e6ea88961936 Mon Sep 17 00:00:00 2001 From: Justin Stein Date: Fri, 12 Oct 2018 11:52:13 -0700 Subject: [PATCH 1/9] Add select account parameter for google authorization Useful for choosing an account if a default account is outside the scope of a G Suite organization. --- app/Auth/Access/SocialAuthService.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Auth/Access/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php index 87db1d5c6..024a1e736 100644 --- a/app/Auth/Access/SocialAuthService.php +++ b/app/Auth/Access/SocialAuthService.php @@ -52,6 +52,9 @@ class SocialAuthService public function startRegister($socialDriver) { $driver = $this->validateDriver($socialDriver); + if ($socialDriver == 'google') { + return $this->socialite->driver($driver)->with(['prompt' => 'select_account'])->redirect(); + } return $this->socialite->driver($driver)->redirect(); } From 77d7f764f1321fda7a2731c8c7ef50cecdea1af8 Mon Sep 17 00:00:00 2001 From: justein230 Date: Fri, 12 Oct 2018 22:50:02 -0700 Subject: [PATCH 2/9] Added else clause --- app/Auth/Access/SocialAuthService.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Auth/Access/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php index 024a1e736..0c26a2950 100644 --- a/app/Auth/Access/SocialAuthService.php +++ b/app/Auth/Access/SocialAuthService.php @@ -55,7 +55,9 @@ class SocialAuthService if ($socialDriver == 'google') { return $this->socialite->driver($driver)->with(['prompt' => 'select_account'])->redirect(); } - return $this->socialite->driver($driver)->redirect(); + else { + return $this->socialite->driver($driver)->redirect(); + } } /** From 79afec9737cee9c9c5ef72576a42dcd3bf6116a9 Mon Sep 17 00:00:00 2001 From: Justin Stein Date: Sat, 13 Oct 2018 14:31:29 -0700 Subject: [PATCH 3/9] Revert "Added else clause" This reverts commit 77d7f764f1321fda7a2731c8c7ef50cecdea1af8. --- app/Auth/Access/SocialAuthService.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Auth/Access/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php index 0c26a2950..024a1e736 100644 --- a/app/Auth/Access/SocialAuthService.php +++ b/app/Auth/Access/SocialAuthService.php @@ -55,9 +55,7 @@ class SocialAuthService if ($socialDriver == 'google') { return $this->socialite->driver($driver)->with(['prompt' => 'select_account'])->redirect(); } - else { - return $this->socialite->driver($driver)->redirect(); - } + return $this->socialite->driver($driver)->redirect(); } /** From 57d99130ee6923b1bbbbe6ee299451d5fd68c70f Mon Sep 17 00:00:00 2001 From: Justin Stein Date: Sat, 13 Oct 2018 14:50:58 -0700 Subject: [PATCH 4/9] Added environment variable for google select account option. --- .env.example | 1 + app/Auth/Access/SocialAuthService.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index eda20ea26..6e015335e 100644 --- a/.env.example +++ b/.env.example @@ -48,6 +48,7 @@ GITHUB_APP_ID=false GITHUB_APP_SECRET=false GOOGLE_APP_ID=false GOOGLE_APP_SECRET=false +GOOGLE_SELECT_ACCOUNT=false OKTA_BASE_URL=false OKTA_APP_ID=false OKTA_APP_SECRET=false diff --git a/app/Auth/Access/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php index 024a1e736..092f5212c 100644 --- a/app/Auth/Access/SocialAuthService.php +++ b/app/Auth/Access/SocialAuthService.php @@ -52,7 +52,7 @@ class SocialAuthService public function startRegister($socialDriver) { $driver = $this->validateDriver($socialDriver); - if ($socialDriver == 'google') { + if ($socialDriver == 'google' && env('GOOGLE_SELECT_ACCOUNT')) { return $this->socialite->driver($driver)->with(['prompt' => 'select_account'])->redirect(); } return $this->socialite->driver($driver)->redirect(); From 216358c6e4faeaafc67c0208f21910282a16d870 Mon Sep 17 00:00:00 2001 From: Justin Stein Date: Sat, 13 Oct 2018 15:14:06 -0700 Subject: [PATCH 5/9] Added Google select account functionality to login --- app/Auth/Access/SocialAuthService.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Auth/Access/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php index 092f5212c..a9adec93e 100644 --- a/app/Auth/Access/SocialAuthService.php +++ b/app/Auth/Access/SocialAuthService.php @@ -40,6 +40,9 @@ class SocialAuthService public function startLogIn($socialDriver) { $driver = $this->validateDriver($socialDriver); + if ($socialDriver == 'google' && env('GOOGLE_SELECT_ACCOUNT')) { + return $this->socialite->driver($driver)->with(['prompt' => 'select_account'])->redirect(); + } return $this->socialite->driver($driver)->redirect(); } From 0283ab11b5f675037dd1634993c5e794edc142ad Mon Sep 17 00:00:00 2001 From: Justin Stein Date: Sun, 4 Nov 2018 10:40:06 -0800 Subject: [PATCH 6/9] Added function for redirect with parameters for Socialite --- app/Auth/Access/SocialAuthService.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app/Auth/Access/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php index a9adec93e..79f6bbd0f 100644 --- a/app/Auth/Access/SocialAuthService.php +++ b/app/Auth/Access/SocialAuthService.php @@ -40,10 +40,7 @@ class SocialAuthService public function startLogIn($socialDriver) { $driver = $this->validateDriver($socialDriver); - if ($socialDriver == 'google' && env('GOOGLE_SELECT_ACCOUNT')) { - return $this->socialite->driver($driver)->with(['prompt' => 'select_account'])->redirect(); - } - return $this->socialite->driver($driver)->redirect(); + return $this->redirectToSocialProvider($driver); } /** @@ -55,10 +52,7 @@ class SocialAuthService public function startRegister($socialDriver) { $driver = $this->validateDriver($socialDriver); - if ($socialDriver == 'google' && env('GOOGLE_SELECT_ACCOUNT')) { - return $this->socialite->driver($driver)->with(['prompt' => 'select_account'])->redirect(); - } - return $this->socialite->driver($driver)->redirect(); + return $this->redirectToSocialProvider($driver); } /** @@ -253,4 +247,19 @@ class SocialAuthService session()->flash('success', trans('settings.users_social_disconnected', ['socialAccount' => title_case($socialDriver)])); return redirect(user()->getEditUrl()); } + + /** + * Provide redirect options per service for the Laravel Socialite driver + * @param $driver + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + public function redirectToSocialProvider($driver) + { + if ($driver == 'google' && config('services.google.select_account')) + { + return $this->socialite->driver($driver)->with(['prompt' => 'select_account'])->redirect(); + } + + return $this->socialite->driver($driver)->redirect(); + } } From c37e73b626e112aa9f36799ee89bac1751d34b9a Mon Sep 17 00:00:00 2001 From: Justin Stein Date: Sun, 4 Nov 2018 10:48:55 -0800 Subject: [PATCH 7/9] Moved redirect functionality back to start register and log in functions --- app/Auth/Access/SocialAuthService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Auth/Access/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php index 79f6bbd0f..62025bf7c 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); + return $this->redirectToSocialProvider($driver)->redirect(); } /** @@ -52,7 +52,7 @@ class SocialAuthService public function startRegister($socialDriver) { $driver = $this->validateDriver($socialDriver); - return $this->redirectToSocialProvider($driver); + return $this->redirectToSocialProvider($driver)->redirect(); } /** @@ -257,9 +257,9 @@ class SocialAuthService { if ($driver == 'google' && config('services.google.select_account')) { - return $this->socialite->driver($driver)->with(['prompt' => 'select_account'])->redirect(); + return $this->socialite->driver($driver)->with(['prompt' => 'select_account']); } - return $this->socialite->driver($driver)->redirect(); + return $this->socialite->driver($driver); } } From 2ca8038df2671573811c7e467045176c26aa3d20 Mon Sep 17 00:00:00 2001 From: Justin Stein Date: Sun, 4 Nov 2018 11:07:04 -0800 Subject: [PATCH 8/9] Removed return from documentation for function redirectToSocialProvider --- app/Auth/Access/SocialAuthService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Auth/Access/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php index 62025bf7c..66f567c98 100644 --- a/app/Auth/Access/SocialAuthService.php +++ b/app/Auth/Access/SocialAuthService.php @@ -251,7 +251,6 @@ class SocialAuthService /** * Provide redirect options per service for the Laravel Socialite driver * @param $driver - * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function redirectToSocialProvider($driver) { From 3abde8bfe2bead0d6e856782902fcfd5ef7ab04d Mon Sep 17 00:00:00 2001 From: Justin Stein Date: Sun, 4 Nov 2018 11:15:58 -0800 Subject: [PATCH 9/9] Added config entry for select account --- config/services.php | 1 + 1 file changed, 1 insertion(+) diff --git a/config/services.php b/config/services.php index 711040386..857a7caa2 100644 --- a/config/services.php +++ b/config/services.php @@ -59,6 +59,7 @@ return [ 'name' => 'Google', 'auto_register' => env('GOOGLE_AUTO_REGISTER', false), 'auto_confirm' => env('GOOGLE_AUTO_CONFIRM_EMAIL', false), + 'select_account' => env('GOOGLE_SELECT_ACCOUNT', false), ], 'slack' => [