@@ -42,7 +42,7 @@ const authSetup = function () {
4242 const IframeLogoutRequestType = "LOGOUT_REQUEST" ;
4343 const enterpriseCustomers = [ 'zurich' , 'cs' ] ;
4444 const mode = qs [ 'mode' ] || 'signIn' ;
45- let returnAppUrl = qs [ 'retUrl' ] ;
45+ let returnAppUrl = handleSpecificReturnUrl ( qs [ 'retUrl' ] , 'retUrl' ) ;
4646 let appUrl = qs [ 'appUrl' ] || false ;
4747
4848 if ( utmSource &&
@@ -88,7 +88,7 @@ const authSetup = function () {
8888 logger ( 'handleRedirectCallback() error: ' , e ) ;
8989 } ) ;
9090 } else if ( shouldLogout ) {
91- host = returnAppUrl ? returnAppUrl : host ;
91+ host = returnAppUrl ? decodeURIComponent ( returnAppUrl ) : host ;
9292 logout ( ) ;
9393 return ;
9494 } else if ( ! isLoggedIn ( ) && returnAppUrl ) {
@@ -179,6 +179,7 @@ const authSetup = function () {
179179 } ;
180180
181181 const login = function ( ) {
182+ logger ( 'returnUrl' , returnAppUrl ) ;
182183 auth0
183184 . loginWithRedirect ( {
184185 redirect_uri : host + '?appUrl=' + returnAppUrl ,
@@ -622,6 +623,45 @@ const authSetup = function () {
622623 document . cookie = cname + "=" + cvalue + cdomain + expires + ";path=/" ;
623624 }
624625
626+ function handleSpecificReturnUrl ( value , param ) {
627+ try {
628+ let hostdomain = "" ;
629+ if ( location . hostname !== 'localhost' ) {
630+ hostdomain = "." + location . hostname . split ( '.' ) . reverse ( ) [ 1 ] +
631+ "." + location . hostname . split ( '.' ) . reverse ( ) [ 0 ] ;
632+ }
633+ const prefixArray = [ 'apps' , 'software' ] ;
634+ if ( hostdomain && value ) {
635+ for ( let i = 0 ; i < prefixArray . length ; i ++ ) {
636+ if ( value . indexOf ( prefixArray [ i ] + hostdomain ) > - 1 ) {
637+ const queryParam = window . location . search . substr ( 1 ) ;
638+ if ( queryParam ) {
639+ const indx = queryParam . indexOf ( param ) ;
640+ if ( indx > - 1 ) {
641+ //assuming queryParam value like retUrl=xxxxxx
642+ const result = queryParam . substring ( indx + param . length + 1 ) ;
643+ // verify broken url : https://abc.com/&utm=abc
644+ logger ( 'handleSpecificReturnUrl: match query result' , result ) ;
645+ if ( result . indexOf ( '&' ) > - 1 && result . indexOf ( '?' ) === - 1 ) {
646+ return value ;
647+ }
648+ return encodeURIComponent ( decodeURIComponent ( result ) ) ;
649+ } else {
650+ return value ;
651+ }
652+ } else {
653+ return value ;
654+ }
655+ }
656+ }
657+ return value ;
658+ }
659+ return value ;
660+ } catch ( e ) {
661+ logger ( 'Issue while handling specific query param function' , e . message ) ;
662+ return value ;
663+ }
664+ } ;
625665
626666 // execute
627667 init ( ) ;
0 commit comments