X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a274406038e13cf678e14d65dfa70d04ead67206..refs/pull/3000/head:/app/Http/Controllers/Auth/LoginController.php diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 01cc77d84..d12d7c9bc 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -43,7 +43,8 @@ class LoginController extends Controller public function __construct(SocialAuthService $socialAuthService, LoginService $loginService) { $this->middleware('guest', ['only' => ['getLogin', 'login']]); - $this->middleware('guard:standard,ldap', ['only' => ['login', 'logout']]); + $this->middleware('guard:standard,ldap', ['only' => ['login']]); + $this->middleware('guard:standard,ldap,oidc', ['only' => ['logout']]); $this->socialAuthService = $socialAuthService; $this->loginService = $loginService; @@ -81,13 +82,7 @@ class LoginController extends Controller } // Store the previous location for redirect after login - $previous = url()->previous(''); - if ($previous && $previous !== url('/https/source.bookstackapp.com/login') && setting('app-public')) { - $isPreviousFromInstance = (strpos($previous, url('/')) === 0); - if ($isPreviousFromInstance) { - redirect()->setIntendedUrl($previous); - } - } + $this->updateIntendedFromPrevious(); return view('auth.login', [ 'socialDrivers' => $socialDrivers, @@ -228,4 +223,32 @@ class LoginController extends Controller $this->username() => [trans('auth.failed')], ])->redirectTo('/login'); } + + /** + * Update the intended URL location from their previous URL. + * Ignores if not from the current app instance or if from certain + * login or authentication routes. + */ + protected function updateIntendedFromPrevious(): void + { + // Store the previous location for redirect after login + $previous = url()->previous(''); + $isPreviousFromInstance = (strpos($previous, url('/')) === 0); + if (!$previous || !setting('app-public') || !$isPreviousFromInstance) { + return; + } + + $ignorePrefixList = [ + '/login', + '/mfa', + ]; + + foreach ($ignorePrefixList as $ignorePrefix) { + if (strpos($previous, url($ignorePrefix)) === 0) { + return; + } + } + + redirect()->setIntendedUrl($previous); + } }