From 419fc166c468c7841b56d691b6e69884cfde6dfa Mon Sep 17 00:00:00 2001 From: Maurizio Vitale Date: Mon, 25 Jan 2021 17:06:35 +0000 Subject: [PATCH] Do redirect before implicit button (#6574) * Do redirect before implicit * Add unit to implicit and silent * Keep the value as it was before --- .../login/components/login.component.spec.ts | 31 +++++++++++++++++-- lib/core/login/components/login.component.ts | 12 ++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/lib/core/login/components/login.component.spec.ts b/lib/core/login/components/login.component.spec.ts index fdc514b79b..abcc478566 100644 --- a/lib/core/login/components/login.component.spec.ts +++ b/lib/core/login/components/login.component.spec.ts @@ -609,14 +609,13 @@ describe('LoginComponent', () => { describe('implicitFlow ', () => { beforeEach(() => { - appConfigService.config.oauth2 = { implicitFlow: true }; + appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: false }; appConfigService.load(); alfrescoApiService.reset(); }); it('should not show login username and password if SSO implicit flow is active', async(() => { spyOn(authService, 'isOauth').and.returnValue(true); - component.ngOnInit(); fixture.detectChanges(); @@ -628,6 +627,34 @@ describe('LoginComponent', () => { }); })); + it('should not render the implicitFlow button in case silentLogin is enabled', async(() => { + spyOn(authService, 'isOauth').and.returnValue(true); + appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: true }; + + spyOn(component, 'redirectToImplicitLogin').and.returnValue(Promise.resolve({})); + + component.ngOnInit(); + fixture.detectChanges(); + + fixture.whenStable().then(() => { + expect(component.implicitFlow).toBe(false); + expect(component.redirectToImplicitLogin).toHaveBeenCalled(); + }); + + })); + + it('should render the implicitFlow button in case silentLogin is disabled', async(() => { + spyOn(authService, 'isOauth').and.returnValue(true); + + component.ngOnInit(); + fixture.detectChanges(); + + fixture.whenStable().then(() => { + expect(component.implicitFlow).toBe(true); + }); + + })); + it('should not show the login base auth button', async(() => { spyOn(authService, 'isOauth').and.returnValue(true); diff --git a/lib/core/login/components/login.component.ts b/lib/core/login/components/login.component.ts index 11b48d57b5..6823ca0ddd 100644 --- a/lib/core/login/components/login.component.ts +++ b/lib/core/login/components/login.component.ts @@ -156,12 +156,10 @@ export class LoginComponent implements OnInit, OnDestroy { if (this.authService.isOauth()) { const oauth: OauthConfigModel = this.appConfig.get(AppConfigValues.OAUTHCONFIG, null); - if (oauth && oauth.implicitFlow) { - this.implicitFlow = true; - } - if (oauth && oauth.silentLogin) { - this.alfrescoApiService.getInstance().oauth2Auth.implicitLogin(); + this.redirectToImplicitLogin(); + } else if (oauth && oauth.implicitFlow) { + this.implicitFlow = true; } } @@ -191,6 +189,10 @@ export class LoginComponent implements OnInit, OnDestroy { this.onSubmit(this.form.value); } + redirectToImplicitLogin() { + this.alfrescoApiService.getInstance().oauth2Auth.implicitLogin(); + } + /** * Method called on submit form * @param values