X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/cc10d1ddfc652f6bcf3bbf61d5ec2e2861394c03..refs/pull/5280/head:/app/Access/Saml2Service.php diff --git a/app/Access/Saml2Service.php b/app/Access/Saml2Service.php index 7f599762e..bb7e9b572 100644 --- a/app/Access/Saml2Service.php +++ b/app/Access/Saml2Service.php @@ -48,20 +48,23 @@ class Saml2Service /** * Initiate a logout flow. + * Returns the SAML2 request ID, and the URL to redirect the user to. * * @throws Error + * @returns array{url: string, id: ?string} */ public function logout(User $user): array { $toolKit = $this->getToolkit(); - $returnRoute = url('/'); + $sessionIndex = session()->get('saml2_session_index'); + $returnUrl = url($this->loginService->logout()); try { $url = $toolKit->logout( - $returnRoute, + $returnUrl, [], $user->email, - session()->get('saml2_session_index'), + $sessionIndex, true, Constants::NAMEID_EMAIL_ADDRESS ); @@ -71,8 +74,7 @@ class Saml2Service throw $error; } - $this->actionLogout(); - $url = '/'; + $url = $returnUrl; $id = null; } @@ -122,7 +124,7 @@ class Saml2Service * * @throws Error */ - public function processSlsResponse(?string $requestId): ?string + public function processSlsResponse(?string $requestId): string { $toolkit = $this->getToolkit(); @@ -131,7 +133,8 @@ class Saml2Service // value so that the exact encoding format is matched when checking the signature. // This is primarily due to ADFS encoding query params with lowercase percent encoding while // PHP (And most other sensible providers) standardise on uppercase. - $redirect = $toolkit->processSLO(true, $requestId, true, null, true); + /** @var ?string $samlRedirect */ + $samlRedirect = $toolkit->processSLO(true, $requestId, true, null, true); $errors = $toolkit->getErrors(); if (!empty($errors)) { @@ -140,18 +143,9 @@ class Saml2Service ); } - $this->actionLogout(); + $defaultBookStackRedirect = $this->loginService->logout(); - return $redirect; - } - - /** - * Do the required actions to log a user out. - */ - protected function actionLogout() - { - auth()->logout(); - session()->invalidate(); + return $samlRedirect ?? $defaultBookStackRedirect; } /**