I need to integrate my website with right signature for signing documents.But I couldn't figured it out because its continously showing me Invalid OAuth Request.
I'm running this api by using php library but its keep on showing Invalid OAuth Request.I'm fed up from all this. Run on Browser below url
https://RightSignature.com/api/documents.xml
You're probably trying to access a file that needs you to have api accesses. If you haven't signed up with them, then you don't have access. If you just want to see the docs, here they are.
EDIT: btw, you need to request an API Key per their docs, and you can't even view their docs until you've signed up for an account. Once you do that, they will personally approve or deny you access to keys. With that, you have about one month to do something with it.
If you have secure token use this code:
For Json response:
Method defines GET or POST,
headers contains header part,
url is rightsignature endpoints,
secure token got after registration,
Body contains parameters.
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Append 'api-token' to Headers
curl_setopt($curl, CURLOPT_HTTPHEADER, array($headers, "api-token: $secure_token")); // Set the headers.
// If you want parameters to be sent
if ($body) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
// Append 'api-token' to Headers
curl_setopt($curl, CURLOPT_HTTPHEADER, array($headers, "Content-Type: application/javascript;charset=utf-8", "api-token: $secure_token"));
}
For XML response:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Append 'api-token' to Headers
curl_setopt($curl, CURLOPT_HTTPHEADER, array($headers, "api-token: $secure_token")); // Set the headers.
// If you want parameters to be sent
if ($body) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
// Append 'api-token' to Headers
curl_setopt($curl, CURLOPT_HTTPHEADER, array($headers, "Content-Type: text/xml;charset=utf-8", "api-token: $secure_token"));
}
Related
So I'm making a Moodle auth plugin for our internal system. For the part of the plugin that syncs updated profile information back to the external API, I need to make a PUT request.
The problem I'm experiencing is that a part of the request is sent through, but then it just stops and eventually the curl operation times out.
My code for making the request:
$curl = curl_init();
$headers = array();
curl_setopt($curl, CURLOPT_PUT, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
array_push($headers, 'Content-Type: application/json');
array_push($headers, 'Expect:');
array_push($headers, 'Connection: keep-alive');
if ($authtoken){
array_push($headers, 'Authorization: Bearer '.$authtoken);
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_URL, $serverurl.'/'.$functionname);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_FAILONERROR,true);
$result = curl_exec($curl);
if (curl_error($curl)){
curl_close($curl);
return false;
}
curl_close($curl);
return $result;
Most of this code works as intended, as it is used for other requests as well and works fine. Specifically for PUT requests like this one, though, it sends around 614 bytes out of the total, for example 614 out of 2324, according to Fiddler, then it stops. Eventually, it times out and I get an error.
So I've fixed it. The solution was to change this line:
curl_setopt($curl, CURLOPT_PUT, 1);
To this:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
I am connecting to Microsoft IIS server from a PHP script using cURL to send some JSON. Everything is working fine, but I don't know what type of authentication I am using.
This is the code:
$curlheader = array("Content-type: application/json", "Auth: N#0062Ibb$#=="); //"Auth:" is changed
$url = "http://xxx.xxx.xxx.xxx:81/feed/ProdICCFeeds/"; //ip is also changed
curl_setopt($curl, CURLOPT_URL, $url); //set url
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true); //http POST
curl_setopt($curl, CURLOPT_HTTPHEADER, $curlheader); //set header
$content = json_encode($aParamsArray); //set paameters, not here
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
What authentication system is that?
Auth is not a standard HTTP request header. You are not using a standard auth mechanism.
I am working with an API that provides a token for me to use to connect. It gives these instructions.
This token is then sent in all subsequent calls to the server in header variable Auth Digest.
I am not sure what this means. I've tried several approaches and read several stack overflow questions. Here's what I've tried. See code comments included for details.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
// I have tried setting both of these
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
// In combination of the above separately, I have tried each of these individually
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $token);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Auth Digest: ' . $token));
curl_setopt($ch, CURLOPT_POST, true);
$post_data = array('Auth Digest' => $token);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
curl_setopt($ch, CURLOPT_USERPWD, $token);
// Then I execute and close, either giving me a failed response and a response that says token is not valid
$response = curl_exec($ch);
$header_sent = curl_getinfo($ch, CURLINFO_HEADER_OUT);
if (!$response) {
echo $action . ' curl request failed';
return false;
}
curl_close($ch);
$response_json = json_decode($response);
var_dump($response_json);
Here are some related stackoverflow questions that I've tried to apply to my problem without success.
Curl request with digest auth in PHP for download Bitbucket private repository
Client part of the Digest Authentication using PHP POST to Web Service
How do I make a request using HTTP basic authentication with PHP curl?
I need to know what the raw http header that they're likely expecting or how I can use php curl to generate the header they're likely expecting.
An digest authorization header typically looks like:
Authorization: Digest _data_here_
So in your case, try:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//... existing options here
$headers = array(
'Authorization: Digest ' . $token,
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
If you use CURLOPT_HTTPHEADER, that just specifies additional headers to send and doesn't require you to add all the headers there.
If the other headers you're sending all have explicit options, use those and just pass the one authorization header to CURLOPT_HTTPHEADER.
So, I have a php script which sends a large JSON object and this is the code I am using to do so.
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_VERBOSE, true);
$json_response = curl_exec($curl);
Now when the data is small, the request goes through smoothly. However, when the json object becomes huge it suddenly fails to send the data and instead is shows "Content-Length: 0" in the request header as if it did not include the object.
I am assuming there is a limit to how large the data could be. Is there a way to bypass that?
I have searched for similar issues and I found a solution for sending files. But the object i have here is a result set from the database and therefore I would prefer to keep the file approach as a last resort.
Thanks.
So basically you have the HTTPHEADER already but you're missing the Content-length one try it like so:
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-length:' . strlen($data)));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_VERBOSE, true);
$json_response = curl_exec($curl);
I've been trying for a while now to call a REST API, but still with no luck.
I've tested the connection, propreties and credentials with WizTools, so I'm 100% all the data is correct and working. Only when I try to connect to the API using custom PHP, things go wrong.
I use Fiddler for debugging and all I see is a request to the local path of the file with the code. For some reason, the snippet isn't calling the REST endpoint... I would like to know how does it come and what do I do wrong...
The code is hosted local (dev.testing.com).
At first sight, I would think the code below is correct, so I'm wondering why I get a GET http://dev.testing.com/talent.php HTTP/1.1 result in Fiddler, while I should get a POST https://api.some_url.com/package/REST/service/criteria?api_key=my_Key HTTP/1.1..
<?php
// Set all the data
$service_url = "https://api.some_url.com/package/REST/service/criteria?api_key=my_Key";
$service_user = 'iiii_My_Username:text:FO';
$service_pass = 'password';
// Initialize the cURL
$ch = curl_init($service_url);
// Set service authentication
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_USERPWD, "{$service_user}:{$service_pass}");
// Composing the HTTP headers
$body = "<searchCriteriaSorting></searchCriteriaSorting>";
$headers = array();
$headers[] = 'Accept: application/xml';
$headers[] = 'Content-Type: application/xml; charset=UTF-8';
// Set the cURL options
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
//WARNING: this would prevent curl from detecting a 'man in the middle' attack
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
// Execute the cURL
$data = curl_exec($ch);
// Print the result
echo $data;
?>