mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-18154 Fix redirect post logout uri (#10122)
This commit is contained in:
@@ -37,11 +37,7 @@ describe('AuthConfigService', () => {
|
|||||||
redirectSilentIframeUri: 'http://localhost:3000/assets/silent-refresh.html',
|
redirectSilentIframeUri: 'http://localhost:3000/assets/silent-refresh.html',
|
||||||
redirectUri: '/',
|
redirectUri: '/',
|
||||||
redirectUriLogout: '#/logout',
|
redirectUriLogout: '#/logout',
|
||||||
publicUrls: [
|
publicUrls: ['**/preview/s/*', '**/settings', '**/logout']
|
||||||
'**/preview/s/*',
|
|
||||||
'**/settings',
|
|
||||||
'**/logout'
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockAuthConfigSubfolderRedirectUri: OauthConfigModel = {
|
const mockAuthConfigSubfolderRedirectUri: OauthConfigModel = {
|
||||||
@@ -54,11 +50,7 @@ describe('AuthConfigService', () => {
|
|||||||
redirectSilentIframeUri: 'http://localhost:3000/subfolder/assets/silent-refresh.html',
|
redirectSilentIframeUri: 'http://localhost:3000/subfolder/assets/silent-refresh.html',
|
||||||
redirectUri: '/subfolder',
|
redirectUri: '/subfolder',
|
||||||
redirectUriLogout: '#/logout',
|
redirectUriLogout: '#/logout',
|
||||||
publicUrls: [
|
publicUrls: ['**/preview/s/*', '**/settings', '**/logout']
|
||||||
'**/preview/s/*',
|
|
||||||
'**/settings',
|
|
||||||
'**/logout'
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockAuthConfigSubfolder2RedirectUri: OauthConfigModel = {
|
const mockAuthConfigSubfolder2RedirectUri: OauthConfigModel = {
|
||||||
@@ -71,11 +63,7 @@ describe('AuthConfigService', () => {
|
|||||||
redirectSilentIframeUri: 'http://localhost:3000/subfolder2/assets/silent-refresh.html',
|
redirectSilentIframeUri: 'http://localhost:3000/subfolder2/assets/silent-refresh.html',
|
||||||
redirectUri: '/subfolder2',
|
redirectUri: '/subfolder2',
|
||||||
redirectUriLogout: '#/logout',
|
redirectUriLogout: '#/logout',
|
||||||
publicUrls: [
|
publicUrls: ['**/preview/s/*', '**/settings', '**/logout']
|
||||||
'**/preview/s/*',
|
|
||||||
'**/settings',
|
|
||||||
'**/logout'
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockAuthConfigSlashRedirectUri: OauthConfigModel = {
|
const mockAuthConfigSlashRedirectUri: OauthConfigModel = {
|
||||||
@@ -88,11 +76,7 @@ describe('AuthConfigService', () => {
|
|||||||
redirectSilentIframeUri: 'http://localhost:3000/assets/silent-refresh.html',
|
redirectSilentIframeUri: 'http://localhost:3000/assets/silent-refresh.html',
|
||||||
redirectUri: '/',
|
redirectUri: '/',
|
||||||
redirectUriLogout: '#/logout',
|
redirectUriLogout: '#/logout',
|
||||||
publicUrls: [
|
publicUrls: ['**/preview/s/*', '**/settings', '**/logout']
|
||||||
'**/preview/s/*',
|
|
||||||
'**/settings',
|
|
||||||
'**/logout'
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockAuthConfigCodeFlow = {
|
const mockAuthConfigCodeFlow = {
|
||||||
@@ -106,19 +90,13 @@ describe('AuthConfigService', () => {
|
|||||||
redirectSilentIframeUri: 'http://localhost:3000/assets/silent-refresh.html',
|
redirectSilentIframeUri: 'http://localhost:3000/assets/silent-refresh.html',
|
||||||
redirectUri: '/',
|
redirectUri: '/',
|
||||||
redirectUriLogout: '#/logout',
|
redirectUriLogout: '#/logout',
|
||||||
publicUrls: [
|
publicUrls: ['**/preview/s/*', '**/settings', '**/logout']
|
||||||
'**/preview/s/*',
|
|
||||||
'**/settings',
|
|
||||||
'**/logout'
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [HttpClientTestingModule],
|
imports: [HttpClientTestingModule],
|
||||||
providers: [
|
providers: [{ provide: AUTH_MODULE_CONFIG, useValue: { useHash: true } }]
|
||||||
{ provide: AUTH_MODULE_CONFIG, useValue: { useHash: true } }
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
service = TestBed.inject(AuthConfigService);
|
service = TestBed.inject(AuthConfigService);
|
||||||
spyOn<any>(service, 'getLocationOrigin').and.returnValue('http://localhost:3000');
|
spyOn<any>(service, 'getLocationOrigin').and.returnValue('http://localhost:3000');
|
||||||
@@ -195,4 +173,52 @@ describe('AuthConfigService', () => {
|
|||||||
expect(service.loadAppConfig().silentRefreshRedirectUri).toBe(expectedUri);
|
expect(service.loadAppConfig().silentRefreshRedirectUri).toBe(expectedUri);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('postLogoutRedirectUri', () => {
|
||||||
|
const getConfig = (config: Partial<OauthConfigModel>): OauthConfigModel => {
|
||||||
|
const defaultConfig = {
|
||||||
|
host: 'http://localhost:3000/auth/realms/alfresco',
|
||||||
|
clientId: 'fakeClientId',
|
||||||
|
scope: 'openid profile email',
|
||||||
|
secret: '',
|
||||||
|
implicitFlow: true,
|
||||||
|
silentLogin: true,
|
||||||
|
redirectSilentIframeUri: 'http://localhost:3000/assets/silent-refresh.html',
|
||||||
|
redirectUri: '/',
|
||||||
|
redirectUriLogout: '/',
|
||||||
|
publicUrls: ['**/preview/s/*', '**/settings', '**/logout']
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
...defaultConfig,
|
||||||
|
...config
|
||||||
|
};
|
||||||
|
};
|
||||||
|
it('should return proper postLogoutRedirectUri when the redirectUriLogout is "/"', () => {
|
||||||
|
const testConfig = getConfig({
|
||||||
|
redirectUriLogout: '/'
|
||||||
|
});
|
||||||
|
|
||||||
|
spyOnProperty(appConfigService, 'oauth2').and.returnValue(testConfig);
|
||||||
|
expect(service.loadAppConfig().postLogoutRedirectUri).toBe('http://localhost:3000/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return proper postLogoutRedirectUri when the redirectUriLogout is empty', () => {
|
||||||
|
const testConfig = getConfig({
|
||||||
|
redirectUriLogout: undefined
|
||||||
|
});
|
||||||
|
|
||||||
|
spyOnProperty(appConfigService, 'oauth2').and.returnValue(testConfig);
|
||||||
|
expect(service.loadAppConfig().postLogoutRedirectUri).toBe('http://localhost:3000/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return proper postLogoutRedirectUri when the redirectUriLogout starts with slash', () => {
|
||||||
|
const testConfig = getConfig({
|
||||||
|
redirectUriLogout: '/asd'
|
||||||
|
});
|
||||||
|
|
||||||
|
spyOnProperty(appConfigService, 'oauth2').and.returnValue(testConfig);
|
||||||
|
expect(service.loadAppConfig().postLogoutRedirectUri).toBe('http://localhost:3000/asd');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -35,10 +35,7 @@ export function authConfigFactory(authConfigService: AuthConfigService): Promise
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class AuthConfigService {
|
export class AuthConfigService {
|
||||||
constructor(
|
constructor(private appConfigService: AppConfigService, @Inject(AUTH_MODULE_CONFIG) private readonly authModuleConfig: AuthModuleConfig) {}
|
||||||
private appConfigService: AppConfigService,
|
|
||||||
@Inject(AUTH_MODULE_CONFIG) private readonly authModuleConfig: AuthModuleConfig
|
|
||||||
) {}
|
|
||||||
|
|
||||||
private _authConfig!: AuthConfig;
|
private _authConfig!: AuthConfig;
|
||||||
get authConfig(): AuthConfig {
|
get authConfig(): AuthConfig {
|
||||||
@@ -62,7 +59,7 @@ export class AuthConfigService {
|
|||||||
nonceStateSeparator: '~',
|
nonceStateSeparator: '~',
|
||||||
redirectUri,
|
redirectUri,
|
||||||
silentRefreshRedirectUri: oauth2.redirectSilentIframeUri,
|
silentRefreshRedirectUri: oauth2.redirectSilentIframeUri,
|
||||||
postLogoutRedirectUri: `${origin}/${oauth2.redirectUriLogout}`,
|
postLogoutRedirectUri: this.generatePostLogoutUri(origin, oauth2.redirectUriLogout),
|
||||||
clientId: oauth2.clientId,
|
clientId: oauth2.clientId,
|
||||||
scope: oauth2.scope,
|
scope: oauth2.scope,
|
||||||
dummyClientSecret: oauth2.secret || '',
|
dummyClientSecret: oauth2.secret || '',
|
||||||
@@ -84,11 +81,10 @@ export class AuthConfigService {
|
|||||||
return oauth2.redirectUri;
|
return oauth2.redirectUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
const locationOrigin = oauth2.redirectUri && oauth2.redirectUri !== '/' ? this.getLocationOrigin() + '' + oauth2.redirectUri : this.getLocationOrigin();
|
const locationOrigin =
|
||||||
|
oauth2.redirectUri && oauth2.redirectUri !== '/' ? this.getLocationOrigin() + '' + oauth2.redirectUri : this.getLocationOrigin();
|
||||||
|
|
||||||
const redirectUri = useHash
|
const redirectUri = useHash ? `${locationOrigin}/#/${viewUrl}` : `${locationOrigin}/${viewUrl}`;
|
||||||
? `${locationOrigin}/#/${viewUrl}`
|
|
||||||
: `${locationOrigin}/${viewUrl}`;
|
|
||||||
|
|
||||||
// handle issue from the OIDC library with hashStrategy and implicitFlow, with would append &state to the url with would lead to error
|
// handle issue from the OIDC library with hashStrategy and implicitFlow, with would append &state to the url with would lead to error
|
||||||
// `cannot match any routes`, and displaying the wildcard ** error page
|
// `cannot match any routes`, and displaying the wildcard ** error page
|
||||||
@@ -98,4 +94,11 @@ export class AuthConfigService {
|
|||||||
private getLocationOrigin() {
|
private getLocationOrigin() {
|
||||||
return window.location.origin;
|
return window.location.origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private generatePostLogoutUri(hostUri: string = '', redirectUriLogout: string = ''): string {
|
||||||
|
const hostUriWithoutSlash = hostUri.endsWith('/') ? hostUri.substring(0, hostUri.length - 1) : hostUri;
|
||||||
|
const redirectUriLogoutWithoutSlash = redirectUriLogout.startsWith('/') ? redirectUriLogout.substring(1) : redirectUriLogout;
|
||||||
|
|
||||||
|
return `${hostUriWithoutSlash}/${redirectUriLogoutWithoutSlash}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user