@@ -149,7 +149,10 @@ function fetchAccessToken() {
149149 curl_setopt ( $ ch , CURLOPT_URL , $ url );
150150 //curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
151151 curl_setopt ( $ ch , CURLOPT_USERAGENT , $ this ->gUserAgent );
152+
152153 curl_setopt ( $ ch , CURLOPT_HEADER , 0 );
154+ $ this ->setCurlHttpHeaders ( $ ch );
155+
153156 curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 );
154157 $ data = curl_exec ( $ ch );
155158
@@ -200,6 +203,7 @@ function fetchAccessToken() {
200203 function sign_request ( $ method , $ url , $ params = [] ) {
201204// global $gConsumerSecret, $gTokenSecret;
202205
206+ $ url = str_replace ( WbstackMagnusOauth::platformIngressHostAndPort, $ _SERVER ['SERVER_NAME ' ], $ url );
203207 $ parts = parse_url ( $ url );
204208
205209 // We need to normalize the endpoint URL
@@ -238,6 +242,24 @@ function sign_request( $method, $url, $params = [] ) {
238242 return base64_encode ( hash_hmac ( 'sha1 ' , $ toSign , $ key , true ) );
239243 }
240244
245+ /**
246+ * Set the HTTP Headers for the curl handle
247+ *
248+ * Sets the HOST parameter when internally talking to wbstack platform ingress
249+ *
250+ */
251+ function setCurlHttpHeaders ( $ curlHandle , $ headers = [] ) {
252+
253+ if ( WbstackMagnusOauth::isLocalHost () ) {
254+ $ domain = $ _SERVER ['SERVER_NAME ' ];
255+ $ headers [] = 'HOST: ' . $ domain ;
256+ }
257+
258+ if ( !empty ($ headers ) ) {
259+ curl_setopt ( $ curlHandle , CURLOPT_HTTPHEADER , $ headers );
260+ }
261+ }
262+
241263 /**
242264 * Request authorization
243265 * @return void
@@ -270,6 +292,7 @@ function doAuthorizationRedirect($callback='') {
270292 //curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
271293 curl_setopt ( $ ch , CURLOPT_USERAGENT , $ this ->gUserAgent );
272294 curl_setopt ( $ ch , CURLOPT_HEADER , 0 );
295+ $ this ->setCurlHttpHeaders ( $ ch );
273296 curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 );
274297 $ data = curl_exec ( $ ch );
275298 if ( !$ data ) {
@@ -482,10 +505,12 @@ function doApiQuery( $post, &$ch = null , $mode = '' , $iterations_left = 5 , $l
482505 curl_setopt ( $ ch , CURLOPT_POST , true );
483506 curl_setopt ( $ ch , CURLOPT_URL , $ url );
484507 curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ post_fields );
485- curl_setopt ( $ ch , CURLOPT_HTTPHEADER , [ $ header ] );
486508 //curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
487509 curl_setopt ( $ ch , CURLOPT_USERAGENT , $ this ->gUserAgent );
510+
488511 curl_setopt ( $ ch , CURLOPT_HEADER , 0 );
512+ $ this ->setCurlHttpHeaders ( $ ch , [ $ header ] );
513+
489514 curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 );
490515
491516 $ data = curl_exec ( $ ch );
0 commit comments