diff --git a/src/core/controllers/AuthenticationController.php b/src/core/controllers/AuthenticationController.php index 6e3e1336217a42e4131b48cc6a8a29cd56ffc863..3bdea6d7a909ba694c6ae882d12c198dd1a548ab 100755 --- a/src/core/controllers/AuthenticationController.php +++ b/src/core/controllers/AuthenticationController.php @@ -313,10 +313,9 @@ class AuthenticationController $loggingMethod = CoreConfigModel::getLoggingMethod(); if ($loggingMethod['id'] == 'cas') { - AuthenticationController::casDisconnection(); + $res = AuthenticationController::casDisconnection(); } - - return $response->withStatus(204); + return $response->withJson(['logoutUrl' => $res['logoutUrl'], 'redirectUrl' => $res['redirectUrl']]); } private static function standardConnection(array $args) @@ -461,9 +460,8 @@ class AuthenticationController } \phpCAS::setFixedServiceURL(UrlController::getCoreUrl() . 'dist/index.html'); \phpCAS::setNoClearTicketsFromUrl(); - \phpCAS::logout(); - - return true; + $logoutUrl = \phpCAS::getServerLogoutURL(); + return ['logoutUrl' => $logoutUrl, 'redirectUrl' => UrlController::getCoreUrl() . 'dist/index.html']; } public function getRefreshedToken(Request $request, Response $response) diff --git a/src/frontend/service/auth.service.ts b/src/frontend/service/auth.service.ts index 6f55e47f48ebd57794842ffe8234c2378d791fec..251fc73f2442c0e34994b6706639b7278312bf25 100644 --- a/src/frontend/service/auth.service.ts +++ b/src/frontend/service/auth.service.ts @@ -5,6 +5,7 @@ import { LocalStorageService } from './local-storage.service'; import { NotificationService } from './notification/notification.service'; import { HeaderService } from './header.service'; import { Observable, Subject } from 'rxjs'; +import { tap } from 'rxjs/operators'; @Injectable({ providedIn: 'root' @@ -89,11 +90,28 @@ export class AuthService { } async logout(cleanUrl: boolean = true) { + if (['cas', 'keycloak'].indexOf(this.authMode) > -1) { + this.SsoLogout(cleanUrl); + } else { + this.redirectAfterLogout(cleanUrl); + await this.router.navigate(['/login']); + } + } + + SsoLogout(cleanUrl: boolean = true) { + this.http.get('../rest/authenticate/logout').pipe( + tap(async (data: any) => { + this.redirectAfterLogout(cleanUrl); + window.location.href = data.logoutUrl + '?service=' + encodeURI(data.redirectUrl); + }) + ).subscribe(); + } + + redirectAfterLogout(cleanUrl: boolean = true) { if (this.getToken() !== null && cleanUrl) { this.cleanUrl(JSON.parse(atob(this.getToken().split('.')[1])).user.id); } this.headerService.setUser(); - await this.router.navigate(['/login']); this.clearTokens(); }