Skip to content

Commit

Permalink
[AAE-18541] - OAuth - redirect does not work (#9133)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikiwanekhyland authored Nov 28, 2023
1 parent 7793aba commit 500c558
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/core/src/lib/auth/guard/auth-guard-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/lib/auth/guard/auth-guard-bpm.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('AuthGuardService BPM', () => {
providers: [
{
provide: OidcAuthenticationService, useValue: {
ssoImplicitLogin: () => { },
ssoLogin: () => { },
isPublicUrl: () => false,
hasValidIdToken: () => false,
isLoggedIn: () => false
Expand All @@ -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,
Expand All @@ -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 () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/lib/auth/guard/auth-guard-ecm.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('AuthGuardService ECM', () => {
providers: [
{
provide: OidcAuthenticationService, useValue: {
ssoImplicitLogin: () => { },
ssoLogin: () => { },
isPublicUrl: () => false,
hasValidIdToken: () => false,
isLoggedIn: () => false
Expand Down Expand Up @@ -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,
Expand All @@ -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 () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/lib/auth/guard/auth-guard.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('AuthGuardService', () => {
providers: [
{
provide: OidcAuthenticationService, useValue: {
ssoImplicitLogin: () => { },
ssoLogin: () => { },
isPublicUrl: () => false,
hasValidIdToken: () => false
}
Expand Down Expand Up @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/lib/auth/services/oidc-authentication.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ export class OidcAuthenticationService extends BaseAuthenticationService {
return this.getUsername();
}

ssoImplicitLogin() {
this.auth.login();
ssoLogin(redirectUrl?: string) {
this.auth.login(redirectUrl);
}

ssoCodeFlowLogin() {
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/lib/login/components/login.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('LoginComponent', () => {
providers: [
{
provide: OidcAuthenticationService, useValue: {
ssoImplicitLogin: () => { },
ssoLogin: () => { },
isPublicUrl: () => false,
hasValidIdToken: () => false,
isLoggedIn: () => false
Expand Down Expand Up @@ -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();
});

}));
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/lib/login/components/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -184,8 +184,8 @@ export class LoginComponent implements OnInit, OnDestroy {
this.onSubmit(this.form.value);
}

redirectToImplicitLogin() {
this.oidcAuthenticationService.ssoImplicitLogin();
redirectToSSOLogin() {
this.oidcAuthenticationService.ssoLogin();
}

/**
Expand All @@ -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();
}

/**
Expand Down

0 comments on commit 500c558

Please sign in to comment.