Change the redirect url using the current page url on shibboleth authentication

This commit is contained in:
Giuseppe Digilio
2020-02-07 13:09:55 +01:00
parent cc4b7b215e
commit 0452a9a8cd
4 changed files with 93 additions and 12 deletions

View File

@@ -9,6 +9,9 @@ import { AuthMethod } from '../../../../core/auth/models/auth.method';
import { CoreState } from '../../../../core/core.reducers';
import { isAuthenticated, isAuthenticationLoading } from '../../../../core/auth/selectors';
import { RouteService } from '../../../../core/services/route.service';
import { NativeWindowRef, NativeWindowService } from '../../../../core/services/window.service';
import { isNotNull } from '../../../empty.util';
@Component({
selector: 'ds-log-in-shibboleth',
@@ -46,10 +49,14 @@ export class LogInShibbolethComponent implements OnInit {
/**
* @constructor
* @param {AuthMethod} injectedAuthMethodModel
* @param {NativeWindowRef} _window
* @param {RouteService} route
* @param {Store<State>} store
*/
constructor(
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
@Inject(NativeWindowService) protected _window: NativeWindowRef,
private route: RouteService,
private store: Store<CoreState>
) {
this.authMethod = injectedAuthMethodModel;
@@ -63,7 +70,26 @@ export class LogInShibbolethComponent implements OnInit {
this.loading = this.store.pipe(select(isAuthenticationLoading));
// set location
this.location = this.injectedAuthMethodModel.location
this.location = decodeURIComponent(this.injectedAuthMethodModel.location);
}
redirectToShibboleth() {
let newLocationUrl = this.location;
const currentUrl = this._window.nativeWindow.location.href;
const myRegexp = /\?redirectUrl=(.*)/g;
const match = myRegexp.exec(this.location);
const redirectUrl = (match && match[1]) ? match[1] : null;
// Check whether the current page is different from the redirect url received from rest
if (isNotNull(redirectUrl) && redirectUrl !== currentUrl) {
// change the redirect url with the current page url
const newRedirectUrl = `?redirectUrl=${currentUrl}`;
newLocationUrl = this.location.replace(/\?redirectUrl=(.*)/g, newRedirectUrl);
}
// redirect to shibboleth authentication url
this._window.nativeWindow.location.href = newLocationUrl;
}
}