mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-17804] Fix login redirection, add redirectUri from the app.config (#9066)
* [AAE-17804] Fix login redirection, add redirectUri from the app.config * [AAE-17804] Updated unit tests
This commit is contained in:
@@ -30,7 +30,58 @@ describe('AuthConfigService', () => {
|
|||||||
|
|
||||||
const mockAuthConfigImplicitFlow: OauthConfigModel = {
|
const mockAuthConfigImplicitFlow: OauthConfigModel = {
|
||||||
host: 'http://localhost:3000/auth/realms/alfresco',
|
host: 'http://localhost:3000/auth/realms/alfresco',
|
||||||
clientId: 'alfresco',
|
clientId: 'fakeClientId',
|
||||||
|
scope: 'openid profile email',
|
||||||
|
secret: '',
|
||||||
|
implicitFlow: true,
|
||||||
|
silentLogin: true,
|
||||||
|
redirectSilentIframeUri: 'http://localhost:3000/assets/silent-refresh.html',
|
||||||
|
redirectUri: '/',
|
||||||
|
redirectUriLogout: '#/logout',
|
||||||
|
publicUrls: [
|
||||||
|
'**/preview/s/*',
|
||||||
|
'**/settings',
|
||||||
|
'**/logout'
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockAuthConfigSubfolderRedirectUri: OauthConfigModel = {
|
||||||
|
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: '/subfolder',
|
||||||
|
redirectUriLogout: '#/logout',
|
||||||
|
publicUrls: [
|
||||||
|
'**/preview/s/*',
|
||||||
|
'**/settings',
|
||||||
|
'**/logout'
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockAuthConfigSubfolder2RedirectUri: OauthConfigModel = {
|
||||||
|
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: '/subfolder2',
|
||||||
|
redirectUriLogout: '#/logout',
|
||||||
|
publicUrls: [
|
||||||
|
'**/preview/s/*',
|
||||||
|
'**/settings',
|
||||||
|
'**/logout'
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockAuthConfigSlashRedirectUri: OauthConfigModel = {
|
||||||
|
host: 'http://localhost:3000/auth/realms/alfresco',
|
||||||
|
clientId: 'fakeClientId',
|
||||||
scope: 'openid profile email',
|
scope: 'openid profile email',
|
||||||
secret: '',
|
secret: '',
|
||||||
implicitFlow: true,
|
implicitFlow: true,
|
||||||
@@ -47,7 +98,7 @@ describe('AuthConfigService', () => {
|
|||||||
|
|
||||||
const mockAuthConfigCodeFlow: OauthConfigModel = {
|
const mockAuthConfigCodeFlow: OauthConfigModel = {
|
||||||
host: 'http://localhost:3000/auth/realms/alfresco',
|
host: 'http://localhost:3000/auth/realms/alfresco',
|
||||||
clientId: 'alfresco',
|
clientId: 'fakeClientId',
|
||||||
scope: 'openid profile email',
|
scope: 'openid profile email',
|
||||||
secret: '',
|
secret: '',
|
||||||
implicitFlow: false,
|
implicitFlow: false,
|
||||||
@@ -86,7 +137,7 @@ describe('AuthConfigService', () => {
|
|||||||
redirectUri: 'http://localhost:3000/#/view/authentication-confirmation/?',
|
redirectUri: 'http://localhost:3000/#/view/authentication-confirmation/?',
|
||||||
silentRefreshRedirectUri: 'http://localhost:3000/silent-refresh.html',
|
silentRefreshRedirectUri: 'http://localhost:3000/silent-refresh.html',
|
||||||
postLogoutRedirectUri: 'http://localhost:3000/#/logout',
|
postLogoutRedirectUri: 'http://localhost:3000/#/logout',
|
||||||
clientId: 'alfresco',
|
clientId: 'fakeClientId',
|
||||||
scope: 'openid profile email',
|
scope: 'openid profile email',
|
||||||
dummyClientSecret: ''
|
dummyClientSecret: ''
|
||||||
};
|
};
|
||||||
@@ -102,7 +153,7 @@ describe('AuthConfigService', () => {
|
|||||||
redirectUri: 'http://localhost:3000/#/view/authentication-confirmation',
|
redirectUri: 'http://localhost:3000/#/view/authentication-confirmation',
|
||||||
silentRefreshRedirectUri: 'http://localhost:3000/silent-refresh.html',
|
silentRefreshRedirectUri: 'http://localhost:3000/silent-refresh.html',
|
||||||
postLogoutRedirectUri: 'http://localhost:3000/#/logout',
|
postLogoutRedirectUri: 'http://localhost:3000/#/logout',
|
||||||
clientId: 'alfresco',
|
clientId: 'fakeClientId',
|
||||||
scope: 'openid profile email',
|
scope: 'openid profile email',
|
||||||
responseType: 'code',
|
responseType: 'code',
|
||||||
dummyClientSecret: ''
|
dummyClientSecret: ''
|
||||||
@@ -112,4 +163,23 @@ describe('AuthConfigService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getRedirectUri', () => {
|
||||||
|
it('should return redirect uri with subfolder path', () => {
|
||||||
|
const expectedUri = 'http://localhost:3000/subfolder/#/view/authentication-confirmation/?';
|
||||||
|
spyOnProperty(appConfigService, 'oauth2').and.returnValue(mockAuthConfigSubfolderRedirectUri);
|
||||||
|
expect(service.getRedirectUri()).toBe(expectedUri);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return redirect uri with subfolder2 path', () => {
|
||||||
|
const expectedUri = 'http://localhost:3000/subfolder2/#/view/authentication-confirmation/?';
|
||||||
|
spyOnProperty(appConfigService, 'oauth2').and.returnValue(mockAuthConfigSubfolder2RedirectUri);
|
||||||
|
expect(service.getRedirectUri()).toBe(expectedUri);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return redirect uri without modeling and admin if redirectUri from app.config is equal to slash', () => {
|
||||||
|
const expectedUri = 'http://localhost:3000/#/view/authentication-confirmation/?';
|
||||||
|
spyOnProperty(appConfigService, 'oauth2').and.returnValue(mockAuthConfigSlashRedirectUri);
|
||||||
|
expect(service.getRedirectUri()).toBe(expectedUri);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -74,12 +74,15 @@ export class AuthConfigService {
|
|||||||
const viewUrl = `view/authentication-confirmation`;
|
const viewUrl = `view/authentication-confirmation`;
|
||||||
const useHash = this.authModuleConfig.useHash;
|
const useHash = this.authModuleConfig.useHash;
|
||||||
|
|
||||||
const redirectUri = useHash
|
|
||||||
? `${this.getLocationOrigin()}/#/${viewUrl}`
|
|
||||||
: `${this.getLocationOrigin()}/${viewUrl}`;
|
|
||||||
|
|
||||||
const oauth2 = this.appConfigService.oauth2;
|
const oauth2 = this.appConfigService.oauth2;
|
||||||
|
|
||||||
|
const locationOrigin = oauth2.redirectUri && oauth2.redirectUri !== '/' ? this.getLocationOrigin() + '' + oauth2.redirectUri : this.getLocationOrigin();
|
||||||
|
|
||||||
|
const redirectUri = useHash
|
||||||
|
? `${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
|
||||||
return oauth2.implicitFlow && useHash ? `${redirectUri}/?` : redirectUri;
|
return oauth2.implicitFlow && useHash ? `${redirectUri}/?` : redirectUri;
|
||||||
|
Reference in New Issue
Block a user