diff --git a/lib/core/services/auth-guard-base.ts b/lib/core/services/auth-guard-base.ts index dfa2ce9589..e165371ac2 100644 --- a/lib/core/services/auth-guard-base.ts +++ b/lib/core/services/auth-guard-base.ts @@ -64,12 +64,14 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild { } protected redirectToUrl(provider: string, url: string) { - this.authenticationService.setRedirect({ provider, url }); + if (!this.isSilentLogin()) { + this.authenticationService.setRedirect({ provider, url }); - const pathToLogin = this.getLoginRoute(); - const urlToRedirect = `/${pathToLogin}?redirectUrl=${url}`; + const pathToLogin = this.getLoginRoute(); + const urlToRedirect = `/${pathToLogin}?redirectUrl=${url}`; - this.router.navigateByUrl(urlToRedirect); + this.router.navigateByUrl(urlToRedirect); + } } protected getLoginRoute(): string { @@ -91,4 +93,13 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild { this.authenticationService.isOauth() && !!oauth && !oauth.silentLogin ); } + + protected isSilentLogin(): boolean { + const oauth = this.appConfigService.get( + AppConfigValues.OAUTHCONFIG, + null + ); + + return this.authenticationService.isOauth() && oauth && oauth.silentLogin; + } } diff --git a/lib/core/services/auth-guard-bpm.service.spec.ts b/lib/core/services/auth-guard-bpm.service.spec.ts index 6951159b56..0adc45fadc 100644 --- a/lib/core/services/auth-guard-bpm.service.spec.ts +++ b/lib/core/services/auth-guard-bpm.service.spec.ts @@ -92,17 +92,6 @@ describe('AuthGuardService BPM', () => { expect(router.navigateByUrl).toHaveBeenCalled(); })); - it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithSilentLogin', async(() => { - spyOn(router, 'navigateByUrl').and.stub(); - spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); - spyOn(authService, 'isOauth').and.returnValue(true); - appConfigService.config.oauth2.silentLogin = true; - const route: RouterStateSnapshot = {url : 'some-url'}; - - expect(authGuard.canActivate(null, route)).toBeFalsy(); - expect(router.navigateByUrl).toHaveBeenCalled(); - })); - it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => { spyOn(router, 'navigateByUrl').and.stub(); spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); diff --git a/lib/core/services/auth-guard-ecm.service.spec.ts b/lib/core/services/auth-guard-ecm.service.spec.ts index 010255fcb1..611d14d83a 100644 --- a/lib/core/services/auth-guard-ecm.service.spec.ts +++ b/lib/core/services/auth-guard-ecm.service.spec.ts @@ -92,17 +92,6 @@ describe('AuthGuardService ECM', () => { expect(router.navigateByUrl).toHaveBeenCalled(); })); - it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithSilentLogin', async(() => { - spyOn(router, 'navigateByUrl').and.stub(); - spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); - spyOn(authService, 'isOauth').and.returnValue(true); - appConfigService.config.oauth2.silentLogin = true; - const route: RouterStateSnapshot = {url : 'some-url'}; - - expect(authGuard.canActivate(null, route)).toBeFalsy(); - expect(router.navigateByUrl).toHaveBeenCalled(); - })); - it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => { spyOn(router, 'navigateByUrl').and.stub(); spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); diff --git a/lib/core/services/auth-guard.service.spec.ts b/lib/core/services/auth-guard.service.spec.ts index 414df6be8b..005f604b22 100644 --- a/lib/core/services/auth-guard.service.spec.ts +++ b/lib/core/services/auth-guard.service.spec.ts @@ -72,7 +72,7 @@ describe('AuthGuardService', () => { expect(authGuard.canActivate(null, route)).toBeTruthy(); })); - it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(() => { + it('should redirect url if the User is NOT logged in and isOAuthWithoutSilentLogin', async(() => { spyOn(router, 'navigateByUrl').and.stub(); spyOn(authService, 'isLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); @@ -82,17 +82,7 @@ describe('AuthGuardService', () => { expect(router.navigateByUrl).toHaveBeenCalled(); })); - it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithSilentLogin', async(() => { - spyOn(router, 'navigateByUrl').and.stub(); - spyOn(authService, 'isLoggedIn').and.returnValue(false); - spyOn(authService, 'isOauth').and.returnValue(true); - appConfigService.config.oauth2.silentLogin = true; - - expect(authGuard.canActivate(null, state)).toBeFalsy(); - expect(router.navigateByUrl).toHaveBeenCalled(); - })); - - it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(() => { + it('should redirect url if the User is NOT logged in and isOAuth but no silentLogin configured', async(() => { spyOn(router, 'navigateByUrl').and.stub(); spyOn(authService, 'isLoggedIn').and.returnValue(false); spyOn(authService, 'isOauth').and.returnValue(true); @@ -102,6 +92,16 @@ describe('AuthGuardService', () => { expect(router.navigateByUrl).toHaveBeenCalled(); })); + it('should NOT redirect url if the User is NOT logged in and isOAuth but with silentLogin configured', async(() => { + spyOn(router, 'navigateByUrl').and.stub(); + spyOn(authService, 'isLoggedIn').and.returnValue(false); + spyOn(authService, 'isOauth').and.returnValue(true); + appConfigService.config.oauth2.silentLogin = true; + + expect(authGuard.canActivate(null, state)).toBeFalsy(); + expect(router.navigateByUrl).not.toHaveBeenCalled(); + })); + it('should set redirect url', async(() => { state.url = 'some-url'; appConfigService.config.loginRoute = 'login';