@@ -79,8 +79,11 @@ module.exports.viewerRequest = async (event) => {
7979 // Destructure special params from query string if they exist.
8080 let {
8181 "ch-code" : chCode ,
82+ "ch-fresh" : chFresh ,
8283 "ch-id" : chID ,
84+ "ch-id-signature" : chIDSignature ,
8385 "ch-public-key" : chPublicKey ,
86+ "ch-requested" : chRequested ,
8487 } = queryString || { } ;
8588
8689 // This is the right most address found in the x-forwarded-for header and can be trusted as it was discovered via the TCP connection.
@@ -94,17 +97,23 @@ module.exports.viewerRequest = async (event) => {
9497 // Remove special params from the queryString object now that we don't need them anymore
9598 if ( queryString ) {
9699 delete queryString [ "ch-code" ] ;
100+ delete queryString [ "ch-fresh" ]
97101 delete queryString [ "ch-id" ] ;
102+ delete queryString [ "ch-id-signature" ] ;
98103 delete queryString [ "ch-public-key" ] ;
104+ delete queryString [ "ch-requested" ] ;
99105 }
100106
101107 // Stringify queryString
102108 queryString = helpers . queryStringParse ( queryString , "string" ) ;
103109 // Prepend & to the query string if it's not empty as we're always going to need to chain it to ?${FQDN}
104110 if ( queryString ) {
111+ //Update the querystring to remove special CH parameters
112+ request . querystring = queryString ;
105113 queryString = `?${ queryString } ` ;
106114 }
107115
116+
108117 //URL encode the targetURL to be used later in redirects
109118 let targetURL ;
110119 if ( queryString ) {
@@ -118,9 +127,11 @@ module.exports.viewerRequest = async (event) => {
118127 let crowdhandlerCookieValue = parsedCookies [ "crowdhandler" ] ;
119128
120129 // Prioritise tokens in the ch-id parameter and fallback to ones found in the cookie.
130+ let freshlyPromoted ;
121131 let token ;
122132 if ( chID ) {
123133 console . log ( "Using ch-id value as token" ) ;
134+ freshlyPromoted = true ;
124135 token = chID ;
125136 } else if ( crowdhandlerCookieValue ) {
126137 console . log ( "Using cookie value as token" ) ;
@@ -129,6 +140,16 @@ module.exports.viewerRequest = async (event) => {
129140 token = null ;
130141 }
131142
143+ if ( freshlyPromoted ) {
144+ let redirectLocation
145+ if ( queryString ) {
146+ redirectLocation = `${ FQDN } ${ queryString } `
147+ } else {
148+ redirectLocation = FQDN
149+ }
150+ return http_helpers . redirect302Response ( redirectLocation , token ) ;
151+ }
152+
132153 // Check in with CrowdHandler
133154 async function checkStatus ( ) {
134155 let headers = {
0 commit comments