@@ -23,7 +23,6 @@ import {
2323 Store ,
2424} from '@ngrx/store' ;
2525import { TranslateService } from '@ngx-translate/core' ;
26- import Cookies from 'js-cookie' ;
2726import {
2827 Observable ,
2928 of ,
@@ -63,6 +62,7 @@ import {
6362import { PageInfo } from '../shared/page-info.model' ;
6463import { URLCombiner } from '../url-combiner/url-combiner' ;
6564import { createSuccessfulRemoteDataObject$ } from '../utilities/remote-data.utils' ;
65+ import { AuthRequestService } from './auth-request.service' ;
6666import {
6767 CheckAuthenticationTokenAction ,
6868 RefreshTokenAction ,
@@ -72,13 +72,12 @@ import {
7272 SetUserAsIdleAction ,
7373 UnsetUserAsIdleAction ,
7474} from './auth.actions' ;
75- import { AuthRequestService } from './auth-request.service' ;
76- import { AuthMethod } from './models/auth.method' ;
7775import { AuthStatus } from './models/auth-status.model' ;
7876import {
7977 AuthTokenInfo ,
8078 TOKENITEM ,
8179} from './models/auth-token-info.model' ;
80+ import { AuthMethod } from './models/auth.method' ;
8281import {
8382 getAuthenticatedUserId ,
8483 getAuthenticationToken ,
@@ -613,20 +612,23 @@ export class AuthService {
613612 */
614613 getExternalServerRedirectUrl ( origin : string , redirectRoute : string , location : string ) : string {
615614 const correctRedirectUrl = new URLCombiner ( origin , redirectRoute ) . toString ( ) ;
615+ const externalServerUrl = new URL ( location , origin ) ;
616+
617+ if ( externalServerUrl . searchParams . has ( 'redirectUrl' ) ) {
618+ externalServerUrl . searchParams . set ( 'redirectUrl' , correctRedirectUrl ) ;
619+ } else if ( externalServerUrl . searchParams . has ( 'redirect_uri' ) ) {
620+ const redirectUri = new URL ( externalServerUrl . searchParams . get ( 'redirect_uri' ) , origin ) ;
621+ redirectUri . searchParams . set ( 'redirectUrl' , correctRedirectUrl ) ;
622+ externalServerUrl . searchParams . set ( 'redirect_uri' , redirectUri . toString ( ) ) ;
623+ } else {
624+ externalServerUrl . searchParams . set ( 'redirectUrl' , correctRedirectUrl ) ;
625+ }
616626
617- let externalServerUrl = location ;
618- const myRegexp = / \? r e d i r e c t U r l = ( .* ) / g;
619- const match = myRegexp . exec ( location ) ;
620- const redirectUrlFromServer = ( match && match [ 1 ] ) ? match [ 1 ] : null ;
621-
622- // Check whether the current page is different from the redirect url received from rest
623- if ( isNotNull ( redirectUrlFromServer ) && redirectUrlFromServer !== correctRedirectUrl ) {
624- // change the redirect url with the current page url
625- const newRedirectUrl = `?redirectUrl=${ correctRedirectUrl } ` ;
626- externalServerUrl = location . replace ( / \? r e d i r e c t U r l = ( .* ) / g, newRedirectUrl ) ;
627+ if ( isNotNull ( location . match ( / ^ h t t p s ? : \/ \/ / ) ) ) {
628+ return externalServerUrl . toString ( ) ;
627629 }
628630
629- return externalServerUrl ;
631+ return ` ${ externalServerUrl . pathname } ${ externalServerUrl . search } ${ externalServerUrl . hash } ` ;
630632 }
631633
632634 /**
0 commit comments