From 500c5581f6fe52e5ba3384b76f11af66990a6bde Mon Sep 17 00:00:00 2001 From: DominikIwanek <141320833+DominikIwanek@users.noreply.github.com> Date: Tue, 28 Nov 2023 17:19:30 +0100 Subject: [PATCH] [AAE-18541] - OAuth - redirect does not work (#9133) --- lib/core/src/lib/auth/guard/auth-guard-base.ts | 2 +- .../src/lib/auth/guard/auth-guard-bpm.service.spec.ts | 6 +++--- .../src/lib/auth/guard/auth-guard-ecm.service.spec.ts | 6 +++--- lib/core/src/lib/auth/guard/auth-guard.service.spec.ts | 6 +++--- .../src/lib/auth/services/oidc-authentication.service.ts | 4 ++-- lib/core/src/lib/login/components/login.component.spec.ts | 6 +++--- lib/core/src/lib/login/components/login.component.ts | 8 ++++---- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/core/src/lib/auth/guard/auth-guard-base.ts b/lib/core/src/lib/auth/guard/auth-guard-base.ts index 036ed6386ed..7727fe546c4 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-base.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-base.ts @@ -98,7 +98,7 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild { return this.navigate(urlToRedirect); } else if (this.getOauthConfig().silentLogin && !this.oidcAuthenticationService.isPublicUrl()) { if (!this.oidcAuthenticationService.hasValidIdToken() || !this.oidcAuthenticationService.hasValidAccessToken()) { - this.oidcAuthenticationService.ssoImplicitLogin(); + this.oidcAuthenticationService.ssoLogin(url); } } else { return this.navigate(urlToRedirect); diff --git a/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts index 14619d26c5c..810d13e9641 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts @@ -45,7 +45,7 @@ describe('AuthGuardService BPM', () => { providers: [ { provide: OidcAuthenticationService, useValue: { - ssoImplicitLogin: () => { }, + ssoLogin: () => { }, isPublicUrl: () => false, hasValidIdToken: () => false, isLoggedIn: () => false @@ -71,7 +71,7 @@ describe('AuthGuardService BPM', () => { spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false); - spyOn(oidcAuthenticationService, 'ssoImplicitLogin').and.stub(); + spyOn(oidcAuthenticationService, 'ssoLogin').and.stub(); appConfigService.config.oauth2 = { silentLogin: true, @@ -86,7 +86,7 @@ describe('AuthGuardService BPM', () => { const route = { url: 'abc' } as RouterStateSnapshot; expect(await authGuard.canActivate(null, route)).toBeFalsy(); - expect(oidcAuthenticationService.ssoImplicitLogin).toHaveBeenCalledTimes(1); + expect(oidcAuthenticationService.ssoLogin).toHaveBeenCalledTimes(1); }); it('if the alfresco js api is logged in should canActivate be true', async () => { diff --git a/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts b/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts index d4c26591db3..e865954443a 100644 --- a/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts +++ b/lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts @@ -44,7 +44,7 @@ describe('AuthGuardService ECM', () => { providers: [ { provide: OidcAuthenticationService, useValue: { - ssoImplicitLogin: () => { }, + ssoLogin: () => { }, isPublicUrl: () => false, hasValidIdToken: () => false, isLoggedIn: () => false @@ -115,7 +115,7 @@ describe('AuthGuardService ECM', () => { spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false); - spyOn(oidcAuthenticationService, 'ssoImplicitLogin').and.stub(); + spyOn(oidcAuthenticationService, 'ssoLogin').and.stub(); appConfigService.config.oauth2 = { silentLogin: true, @@ -129,7 +129,7 @@ describe('AuthGuardService ECM', () => { const route = {url : 'abc'} as RouterStateSnapshot; expect(await authGuard.canActivate(null, route)).toBeFalsy(); - expect(oidcAuthenticationService.ssoImplicitLogin).toHaveBeenCalledTimes(1); + expect(oidcAuthenticationService.ssoLogin).toHaveBeenCalledTimes(1); }); it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async () => { 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 96ef8d0eb6a..062d4e708fc 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 @@ -45,7 +45,7 @@ describe('AuthGuardService', () => { providers: [ { provide: OidcAuthenticationService, useValue: { - ssoImplicitLogin: () => { }, + ssoLogin: () => { }, isPublicUrl: () => false, hasValidIdToken: () => false } @@ -125,13 +125,13 @@ describe('AuthGuardService', () => { }); it('should NOT redirect url if the User is NOT logged in and isOAuth but with silentLogin configured', async () => { - spyOn(oidcAuthenticationService, 'ssoImplicitLogin').and.stub(); + spyOn(oidcAuthenticationService, 'ssoLogin').and.stub(); spyOn(authService, 'isLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); appConfigService.config.oauth2.silentLogin = true; expect(await authGuard.canActivate(null, state)).toBeFalsy(); - expect(oidcAuthenticationService.ssoImplicitLogin).toHaveBeenCalledTimes(1); + expect(oidcAuthenticationService.ssoLogin).toHaveBeenCalledTimes(1); }); it('should set redirect url', async () => { diff --git a/lib/core/src/lib/auth/services/oidc-authentication.service.ts b/lib/core/src/lib/auth/services/oidc-authentication.service.ts index 508e1c3abe1..01d81331445 100644 --- a/lib/core/src/lib/auth/services/oidc-authentication.service.ts +++ b/lib/core/src/lib/auth/services/oidc-authentication.service.ts @@ -138,8 +138,8 @@ export class OidcAuthenticationService extends BaseAuthenticationService { return this.getUsername(); } - ssoImplicitLogin() { - this.auth.login(); + ssoLogin(redirectUrl?: string) { + this.auth.login(redirectUrl); } ssoCodeFlowLogin() { diff --git a/lib/core/src/lib/login/components/login.component.spec.ts b/lib/core/src/lib/login/components/login.component.spec.ts index b52059ede1d..34a5d372834 100644 --- a/lib/core/src/lib/login/components/login.component.spec.ts +++ b/lib/core/src/lib/login/components/login.component.spec.ts @@ -65,7 +65,7 @@ describe('LoginComponent', () => { providers: [ { provide: OidcAuthenticationService, useValue: { - ssoImplicitLogin: () => { }, + ssoLogin: () => { }, isPublicUrl: () => false, hasValidIdToken: () => false, isLoggedIn: () => false @@ -715,14 +715,14 @@ describe('LoginComponent', () => { spyOn(authService, 'isOauth').and.returnValue(true); appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: true }; - spyOn(component, 'redirectToImplicitLogin').and.stub(); + spyOn(component, 'redirectToSSOLogin').and.stub(); component.ngOnInit(); fixture.detectChanges(); fixture.whenStable().then(() => { expect(component.ssoLogin).toBe(false); - expect(component.redirectToImplicitLogin).toHaveBeenCalled(); + expect(component.redirectToSSOLogin).toHaveBeenCalled(); }); })); diff --git a/lib/core/src/lib/login/components/login.component.ts b/lib/core/src/lib/login/components/login.component.ts index 55b5ecc1fd2..d8c5da2154f 100644 --- a/lib/core/src/lib/login/components/login.component.ts +++ b/lib/core/src/lib/login/components/login.component.ts @@ -154,7 +154,7 @@ export class LoginComponent implements OnInit, OnDestroy { if (this.authService.isOauth()) { const oauth = this.appConfig.oauth2; if (oauth?.silentLogin) { - this.redirectToImplicitLogin(); + this.redirectToSSOLogin(); } else if (oauth?.implicitFlow || oauth?.codeFlow) { this.ssoLogin = true; } @@ -184,8 +184,8 @@ export class LoginComponent implements OnInit, OnDestroy { this.onSubmit(this.form.value); } - redirectToImplicitLogin() { - this.oidcAuthenticationService.ssoImplicitLogin(); + redirectToSSOLogin() { + this.oidcAuthenticationService.ssoLogin(); } /** @@ -212,7 +212,7 @@ export class LoginComponent implements OnInit, OnDestroy { if (this.authService.isLoggedIn()) { this.router.navigate([this.successRoute]); } - this.oidcAuthenticationService.ssoImplicitLogin(); + this.oidcAuthenticationService.ssoLogin(); } /**