[AAE-18541] - OAuth - redirect does not work (#9133)

This commit is contained in:
DominikIwanek
2023-11-28 17:19:30 +01:00
committed by GitHub
parent 7793aba89e
commit 500c5581f6
7 changed files with 19 additions and 19 deletions

View File

@@ -98,7 +98,7 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
return this.navigate(urlToRedirect); return this.navigate(urlToRedirect);
} else if (this.getOauthConfig().silentLogin && !this.oidcAuthenticationService.isPublicUrl()) { } else if (this.getOauthConfig().silentLogin && !this.oidcAuthenticationService.isPublicUrl()) {
if (!this.oidcAuthenticationService.hasValidIdToken() || !this.oidcAuthenticationService.hasValidAccessToken()) { if (!this.oidcAuthenticationService.hasValidIdToken() || !this.oidcAuthenticationService.hasValidAccessToken()) {
this.oidcAuthenticationService.ssoImplicitLogin(); this.oidcAuthenticationService.ssoLogin(url);
} }
} else { } else {
return this.navigate(urlToRedirect); return this.navigate(urlToRedirect);

View File

@@ -45,7 +45,7 @@ describe('AuthGuardService BPM', () => {
providers: [ providers: [
{ {
provide: OidcAuthenticationService, useValue: { provide: OidcAuthenticationService, useValue: {
ssoImplicitLogin: () => { }, ssoLogin: () => { },
isPublicUrl: () => false, isPublicUrl: () => false,
hasValidIdToken: () => false, hasValidIdToken: () => false,
isLoggedIn: () => false isLoggedIn: () => false
@@ -71,7 +71,7 @@ describe('AuthGuardService BPM', () => {
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false); spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true); spyOn(authService, 'isOauth').and.returnValue(true);
spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false); spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false);
spyOn(oidcAuthenticationService, 'ssoImplicitLogin').and.stub(); spyOn(oidcAuthenticationService, 'ssoLogin').and.stub();
appConfigService.config.oauth2 = { appConfigService.config.oauth2 = {
silentLogin: true, silentLogin: true,
@@ -86,7 +86,7 @@ describe('AuthGuardService BPM', () => {
const route = { url: 'abc' } as RouterStateSnapshot; const route = { url: 'abc' } as RouterStateSnapshot;
expect(await authGuard.canActivate(null, route)).toBeFalsy(); 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 () => { it('if the alfresco js api is logged in should canActivate be true', async () => {

View File

@@ -44,7 +44,7 @@ describe('AuthGuardService ECM', () => {
providers: [ providers: [
{ {
provide: OidcAuthenticationService, useValue: { provide: OidcAuthenticationService, useValue: {
ssoImplicitLogin: () => { }, ssoLogin: () => { },
isPublicUrl: () => false, isPublicUrl: () => false,
hasValidIdToken: () => false, hasValidIdToken: () => false,
isLoggedIn: () => false isLoggedIn: () => false
@@ -115,7 +115,7 @@ describe('AuthGuardService ECM', () => {
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false); spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true); spyOn(authService, 'isOauth').and.returnValue(true);
spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false); spyOn(oidcAuthenticationService, 'isPublicUrl').and.returnValue(false);
spyOn(oidcAuthenticationService, 'ssoImplicitLogin').and.stub(); spyOn(oidcAuthenticationService, 'ssoLogin').and.stub();
appConfigService.config.oauth2 = { appConfigService.config.oauth2 = {
silentLogin: true, silentLogin: true,
@@ -129,7 +129,7 @@ describe('AuthGuardService ECM', () => {
const route = {url : 'abc'} as RouterStateSnapshot; const route = {url : 'abc'} as RouterStateSnapshot;
expect(await authGuard.canActivate(null, route)).toBeFalsy(); 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 () => { it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async () => {

View File

@@ -45,7 +45,7 @@ describe('AuthGuardService', () => {
providers: [ providers: [
{ {
provide: OidcAuthenticationService, useValue: { provide: OidcAuthenticationService, useValue: {
ssoImplicitLogin: () => { }, ssoLogin: () => { },
isPublicUrl: () => false, isPublicUrl: () => false,
hasValidIdToken: () => 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 () => { 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, 'isLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true); spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2.silentLogin = true; appConfigService.config.oauth2.silentLogin = true;
expect(await authGuard.canActivate(null, state)).toBeFalsy(); expect(await authGuard.canActivate(null, state)).toBeFalsy();
expect(oidcAuthenticationService.ssoImplicitLogin).toHaveBeenCalledTimes(1); expect(oidcAuthenticationService.ssoLogin).toHaveBeenCalledTimes(1);
}); });
it('should set redirect url', async () => { it('should set redirect url', async () => {

View File

@@ -138,8 +138,8 @@ export class OidcAuthenticationService extends BaseAuthenticationService {
return this.getUsername(); return this.getUsername();
} }
ssoImplicitLogin() { ssoLogin(redirectUrl?: string) {
this.auth.login(); this.auth.login(redirectUrl);
} }
ssoCodeFlowLogin() { ssoCodeFlowLogin() {

View File

@@ -65,7 +65,7 @@ describe('LoginComponent', () => {
providers: [ providers: [
{ {
provide: OidcAuthenticationService, useValue: { provide: OidcAuthenticationService, useValue: {
ssoImplicitLogin: () => { }, ssoLogin: () => { },
isPublicUrl: () => false, isPublicUrl: () => false,
hasValidIdToken: () => false, hasValidIdToken: () => false,
isLoggedIn: () => false isLoggedIn: () => false
@@ -715,14 +715,14 @@ describe('LoginComponent', () => {
spyOn(authService, 'isOauth').and.returnValue(true); spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: true }; appConfigService.config.oauth2 = { implicitFlow: true, silentLogin: true };
spyOn(component, 'redirectToImplicitLogin').and.stub(); spyOn(component, 'redirectToSSOLogin').and.stub();
component.ngOnInit(); component.ngOnInit();
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
expect(component.ssoLogin).toBe(false); expect(component.ssoLogin).toBe(false);
expect(component.redirectToImplicitLogin).toHaveBeenCalled(); expect(component.redirectToSSOLogin).toHaveBeenCalled();
}); });
})); }));

View File

@@ -154,7 +154,7 @@ export class LoginComponent implements OnInit, OnDestroy {
if (this.authService.isOauth()) { if (this.authService.isOauth()) {
const oauth = this.appConfig.oauth2; const oauth = this.appConfig.oauth2;
if (oauth?.silentLogin) { if (oauth?.silentLogin) {
this.redirectToImplicitLogin(); this.redirectToSSOLogin();
} else if (oauth?.implicitFlow || oauth?.codeFlow) { } else if (oauth?.implicitFlow || oauth?.codeFlow) {
this.ssoLogin = true; this.ssoLogin = true;
} }
@@ -184,8 +184,8 @@ export class LoginComponent implements OnInit, OnDestroy {
this.onSubmit(this.form.value); this.onSubmit(this.form.value);
} }
redirectToImplicitLogin() { redirectToSSOLogin() {
this.oidcAuthenticationService.ssoImplicitLogin(); this.oidcAuthenticationService.ssoLogin();
} }
/** /**
@@ -212,7 +212,7 @@ export class LoginComponent implements OnInit, OnDestroy {
if (this.authService.isLoggedIn()) { if (this.authService.isLoggedIn()) {
this.router.navigate([this.successRoute]); this.router.navigate([this.successRoute]);
} }
this.oidcAuthenticationService.ssoImplicitLogin(); this.oidcAuthenticationService.ssoLogin();
} }
/** /**