From d7882feb0dc02ef06b1b7cbf5cfa8d01191d0c8d Mon Sep 17 00:00:00 2001 From: Mykyta Maliarchuk Date: Mon, 18 Nov 2024 09:26:17 +0100 Subject: [PATCH] [ACS-8961] Emit onLogout when redirected to login page --- .../src/lib/auth/guard/auth-guard.service.spec.ts | 11 +++++++++++ lib/core/src/lib/auth/guard/auth-guard.service.ts | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts index 565f066330a..bea48fd1570 100644 --- a/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard.service.spec.ts @@ -171,6 +171,17 @@ describe('AuthGuardService', () => { expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url')); }); + it('should emit onLogout if the user is NOT logged in and basic authentication is used', async () => { + spyOn(authService, 'isLoggedIn').and.returnValue(false); + spyOn(authService, 'isOauth').and.returnValue(false); + appConfigService.config.loginRoute = 'login'; + spyOn(basicAlfrescoAuthService.onLogout, 'next'); + + await TestBed.runInInjectionContext(() => AuthGuard(route, state)); + + expect(basicAlfrescoAuthService.onLogout.next).toHaveBeenCalledWith(true); + }); + it('should set redirect url with query params', async () => { state.url = 'some-url;q=query'; appConfigService.config.loginRoute = 'login'; diff --git a/lib/core/src/lib/auth/guard/auth-guard.service.ts b/lib/core/src/lib/auth/guard/auth-guard.service.ts index 48962f08079..c8cabbfad74 100644 --- a/lib/core/src/lib/auth/guard/auth-guard.service.ts +++ b/lib/core/src/lib/auth/guard/auth-guard.service.ts @@ -67,12 +67,12 @@ export class AuthGuardService { provider: this.getProvider(), url }); - + this.basicAlfrescoAuthService.onLogout.next(true); urlToRedirect = `${urlToRedirect}?redirectUrl=${url}`; return this.navigate(urlToRedirect); } else if (this.getOauthConfig().silentLogin && !this.oidcAuthenticationService.isPublicUrl()) { const shouldPerformSsoLogin = await new Promise((resolve) => { - this.oidcAuthenticationService.shouldPerformSsoLogin$.subscribe(value => resolve(value)); + this.oidcAuthenticationService.shouldPerformSsoLogin$.subscribe((value) => resolve(value)); }); if (shouldPerformSsoLogin) { this.oidcAuthenticationService.ssoLogin(url);