I am new to curl. I'm trying basic authentication using curl with pivotal tracker
error:{"error":"Needs authentication credentials.","possible_fix":"Try basic auth, or include header X-TrackerToken.","code":"unauthenticated","kind":"error".
here is simple code i used to authenticate:
$ch = curl_init();
$data = array('$token'=>'858e234da*****');
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://www.pivotaltracker.com/services/v5/me");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// grab URL and pass it to the browser
$response =curl_exec($ch);
var_dump($response);
// close cURL resource, and free up system resources
curl_close($ch);
how to authenticate my application with token as pivotal tracker support simple ouath authentication.
i would like to explain steps of authentication
a.)user enter user name and password.
b.)then enter token of your profile.
c.) now page is redirected your dashboard.
Try basic auth, or include header X-TrackerToken.
Which seems to me is asking you to submit the token as a X-TrackerToken header.
You can try something like this, though I can't find the pivotaltracker documentation.
$ch = curl_init('https://www.pivotaltracker.com/services/v5/me');
// or just remove the customrequest too
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-TrackerToken: 858e234da*****'
);
$result = curl_exec($ch);
curl_close($ch);
update
Found the documentation.
It shows something like:
export TOKEN='your Pivotal Tracker API token'
curl -X GET -H "X-TrackerToken: $TOKEN" "https://www.pivotaltracker.com/services/edge/stories/558"
Related
I just want to get the authorization code to obtain the access token to make API requests, I did the step manaully through the pasting the link in the browser and it works.
but through Curl PHP doesn't work I get empty string of size 1400 char.
this's the sample on Quickbooks API doc
curl -X POST 'https://appcenter.intuit.com/connect/oauth2?
client_id=Q3ylJatCvnkYqVKLmkxxxxxxxxxxxxxxxkYB36b5mws7HkKUEv9aI&response_type=code&
scope=com.intuit.quickbooks.accounting&
redirect_uri=https://www.mydemoapp.com/oauth-redirect&
state=security_token%3D138r5719ru3e1%26url%3Dhttps://www.mydemoapp.com/oauth-redirect'
Quickbooks API Auth code ref
I Turned to Curl PHP with replacing my credentials, when I visit the link I get the auth code and I could obtian the access token but can't do it in the back-end
the dir of the page that I want to get the auth code in is https://roifelawgroup.com/clientform/login/info_submit.php
but the redirect link just : https://roifelawgroup.com/ with login creds is this could be the problem?
However I tried with the same page redirect link didn't work
function authcode(){
$url = "https://appcenter.intuit.com/connect/oauth2?client_id=ABfQBA8VYPPUETO5isi2v8p39lQwEsw1ozL7NhZxxxxxx&response_type=code&scope=com.intuit.quickbooks.payment&redirect_uri=https://roifelawgroup.com&state=security_token%3D138r5719ru3e1%26url%3Dhttps://roifelawgroup.com";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // if removed this line I get 301 permanently moved
$headers = array(
"Content-Length: 0",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
}
To authenticate API calls, you must first generate a session to get a token. Then you must send the session token as the value of the X-Auth-Token header to authenticate API calls.
To create a session you first need to manually generate an API Key. This is a key/value pair that can be generated in the API Access page. When you click Generate New API Key, a popup will be displayed with the API Key Value and in the table of Active Keys you can find the API Key ID. This is then sent via Basic Authentication in a POST call to the sessions route.
I followed this Api Documentation of deepcrawl already but what am I doing wrong?
I have X-Auth-Token and API KEY ID where should I put this?
$deephead = "X-Auth-Token: asdjasiojqoieuqiouwqpofoqwojeq";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.deepcrawl.com/sessions");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $deephead);
// Get the response
$response = curl_exec($ch);
// Close cURL connection
curl_close($ch);
// Decode the response (Transform it to an Array)
$result = json_decode($response);
//debug the response
dd($result);
The I can't even get to CURLOPT_GET cause at my post I only get null value. Any idea/thoughts how can I fix this. Thank you in advance.
DeepCrawl API
It looks like you are trying to generate a token, which it looks like you already have.
To authenticate API calls, you must first generate a session to get a
token. Then you must send the session token as the value of the
X-Auth-Token header to authenticate API calls.
To create a session you first need to manually generate an API Key.
This is a key/value pair that can be generated in the API Access page.
When you click Generate New API Key, a popup will be displayed with
the API Key Value and in the table of Active Keys you can find the API
Key ID. This is then sent via Basic Authentication in a POST call to
the sessions route.
curl -X POST -u '123:abcdef' https://api.deepcrawl.com/sessions {
"token":"abcdef123", "_user_href":"/users/example-user", ... }
Not the clearest, but it's right there.
$headers = [
'Content-Type: application/x-www-form-urlencoded',
'accept: text/html'
];
$username='yourusername';
$password='supersecret';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.deepcrawl.com/sessions");
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "root=1");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Get the response
$response = curl_exec($ch);
// Close cURL connection
curl_close($ch);
// Decode the response (Transform it to an Array)
return json_decode($response);
That will return something like
{
"token":"abcdef123",
"_user_href":"/users/example-user",
...
}
Since you already have the token, you don't need ot hit session. you can just make your calls.
$headers = [
'X-AUTH-TOKEN: your-api-key',
'accept: text/html'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.deepcrawl.com/system_statuses");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Get the response
$response = curl_exec($ch);
// Close cURL connection
curl_close($ch);
// Decode the response (Transform it to an Array)
return json_decode($response);
I am trying to hit api which is having OAuth1.0.
Problem is when i am trying with Postman i am getting response but with PHP curl its giving error.
In postman i am passing parameters as below
url='xxxx', Authentication stuff is type=OAuth1.0,Consumer Key,Consumer Secret, Token, Token Secret, Timestamp, Nonce, Version=1.0, Realm=Optional
Below is my code which i have tried
$url="xxx";
$header[] = 'Content-Type: application/x-www-form-urlencoded';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode('Authorization:OAuth oauth_consumer_key="xxx",oauth_token="xxx",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1475651061",oauth_nonce="LyA5sR",oauth_version="1.0",oauth_signature="xxx"'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
if(curl_error($ch))
{
echo 'error:' . curl_error($ch);
}
echo "<pre>";print_r($result);exit;
I have added CURLOPT_SSL_VERIFYPEER, because there was certification problem. Now i am getting 'Access denied' from api curl error 403 because there is something wrong in the way i am passing for Oauth 1.0 by curl.
This is the first time i am trying outh1.0 with curl. Please help me whats going on in my code. I have tried using this link
The issue is with oauth signature which is not getting formed properly. You can refer https://oauth.net/core/1.0/ for more clarity
Short version: Is there a way that my PHP application can login to a certain Dropbox account by doing the complete OAuth 2.0 process server-side?
Long version: Consider the following steps:
Navigate Google Chrome to the login page my Dropbox app: https://www.dropbox.com/1/oauth2/authorize?locale=&response_type=code&client_id=[APP_CLIENT_ID]
Open Chrome Dev Tools, go to console
Issue the following jQuery call:
jQuery.ajax({
method: 'POST',
url: 'https://www.dropbox.com/ajax_login',
data: {
login_email: '[DROPBOX_LOGIN]',
login_password: '[DROPBOX_PASSWORD]',
require_role: ''
},
});
Now this browser is logged into Dropbox, which can be seen by refreshing the browser window.
How can I implement the same procedure in PHP, using cURL or file_get_contents?
I tried it like this:
<?php
require_once "config.php";
use \Dropbox as dbx;
// init Dropbox login process
$webAuth = new dbx\WebAuthNoRedirect($appInfo, $clientId);
$authorizeUrl = $webAuth->start();
// load Dropbox login website
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
$ch = curl_init($authorizeUrl);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch);
$data = array('login_email' => '[DROPBOX_LOGIN]', 'login_password' => '[DROPBOX_PASSWORD]', 'require_role' => '');
$loginUrl = 'https://www.dropbox.com/ajax_login';
$ch = curl_init($loginUrl);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded',
'Connection: Keep-Alive'
));
$result = curl_exec ($ch);
if ($result === FALSE)
$result = curl_error($ch) . ' ' . curl_errno($ch);
But I always end up with a 403 Forbidden.
What am I doing wrong?
Btw I have a legitimate use case for this. I know that Dropbox uses OAuth 2.0 to prevent the user's password from going to my server. But the credentials which are used here are not from the end-user.
Just complete the OAuth flow once for the target account and save the access token. Then you can use that access token indefinitely.
(If the access token is for the developer account that owns the app, you can skip the OAuth flow altogether and just click the "Generate" button in the app console to get an access token for your own account.)
I have the following code to delete a YouTube video using cURL. I'm getting a 401 response/authorization error. I've put in the API key in the url and do I put the access token in the bearer value in CURLOPT_HTTPHEADER area?
$url = "https://www.googleapis.com/youtube/v3/videos?id=VIDEO_ID_HERE&key=KEY_HERE";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Content-type: application/json','Authorization : Bearer '.$_SESSION['access_token']));
$result = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
Are there any other mistakes I'm making?
Okay I had another question on the same topic (deleting videos) so I'll post that answer here now that I've figured it out in case someone finds this via Google. I never figured out the cURL method but the method using the google PHP library for v3 of their API is as follows:
$youtube = new Google_Service_YouTube($client);
...
//do your authoraisation stuff + getting access token etc
...
$youtube->videos->delete('<Your Video ID>');
Hope that helps!