dreamfactorysoftware / df-rws

The DreamFactory Remote Web Service package.
Apache License 2.0
1 stars 6 forks source link

Headers not getting passed through. #3

Closed hellokirk closed 7 years ago

hellokirk commented 7 years ago

I'm calling a Remote Service, HTTP Service from another PHP Scripting service like this:

$get = $platform['api']->get;
$options['headers']['Authorization'] = "OAuth2 $token";
$response = $get('myService/user', "my payload", $options);

The documentation shows it here, but I don't think those headers values are being passed through correctly.

todda48 commented 7 years ago

If you want DreamFactory to pass on specific headers to the remote HTTP service you can set that in the Config tab for the remote service. From the Services tab select the HTTP service and go to the Config tab. Under the 'Headers' section add a new entry and enter the name of the header and check 'Pass From Client'. Select all verbs and save the config.

hellokirk commented 7 years ago

So from a scripting service how would I pass a variable value into a header key? I tried setting up an 'Authorization' key in the config (tried both a null value and a placeholder value), but the value I pass in from my scripting service still seems to be ignored.

todda48 commented 7 years ago

See the section on adding HTTP headers. Let me know if it helps.

http://wiki.dreamfactory.com/DreamFactory/Features/Scripting#Resources_Available_To_A_Script

If you want the header sent on to the remote service you have to set up the header in the service config as previously mentioned.

$url = 'http://example.com/my_api';
$payload = json_decode("{\"name\":\"test\"}", true);
$options = [];
$options['headers'] = [];
$options['headers']['Content-Type'] = 'application/json';
$options['parameters'] = [];
$options['parameters']['api_key'] = 'my_api_key';
$api = $platform['api'];
$post = $api->post;
$result = $post($url, $payload, $options);
var_dump($result);
hellokirk commented 7 years ago

Thank you, but unfortunately, it does not help. That is the example I followed to get to my issue in the first place. I have the 'Authorization' header key set in the config and it works fine when run from the api docs or from another script without trying to change the key; however, I still can't get that header value to change when using the platform api resource.

I've tried a couple different methods to invalidate the value that's in the config: $options['headers']['Authorization'] = 'bogus';

cURL options can include HTTP headers using CURLOPT_HTTPHEADER, but it's recommended to use options.headers for V8js or $options['headers'] for PHP to send headers as shown above.

Despite that warning, I've also tried things like:

$options[CURLOPT_HTTPHEADER][] = 'Authorization: bogus';

todda48 commented 7 years ago

Ok got it. Looking into this with engineering team. Will report back soon.

todda48 commented 7 years ago

Lee fixed this in develop branch of df-rws. I used requestbin to verify that headers were passed through properly when calling HTTP service from a script.