[Iplant-api-dev] token retrieval not working
Rion Dooley
dooley at tacc.utexas.edu
Wed Jan 7 10:16:16 MST 2015
You’ve got a couple php errors in your code and you’re not serializing the form before passing it to curl. Try this code and remember to encode your password if it contains special characters. Also, check out the Agave php sdk.
<?php
$base_url = 'https://agave.iplantc.org';
$username = '';
$password = '';
$consumer_key = '';
$consumer_secret = '';
$post_params = array(
"grant_type=password",
"username=${username}",
"password=${password}",
"scope=PRODUCTION"
);
$query_string = implode('&', $post_params);
echo $query_string."\n";
$ch = curl_init();
$url="${base_url}/token";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type:application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERPWD, "${consumer_key}:${consumer_secret}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
$response = curl_exec($ch);
$headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT );
echo $headerSent."\n";
echo $response."\n";
curl_close($ch);
?>
—
Rion
On Jan 7, 2015, at 10:17 AM, Duvick, Jonathan P [GDCBS] <jduvick at iastate.edu<mailto:jduvick at iastate.edu>> wrote:
I'm refactoring an Atmosphere VM for Agave, accomplished via Web forms generated by PHP, and I've succeeded in getting step 1 (client app registration/retrieve keys) accomplished. Step 2 (retrieve auth token and refresh token) is not working. It always returns http_code '400' in response to my curl request, suggesting malformed syntax.
Can anyone spot a problem in this code? My client app ('xGDBvm') is successfully registered (it shows up onhttps://agave.iplantc.org/store/site/pages/applications.jag)<https://agave.iplantc.org/store/site/pages/applications.jag> and I am successfully passing the associated consumer key/_secret string values in the curl request after retrieving them from a MySQL table. In the snippet below, $base_url is https://agave.iplantc.org.<https://agave.iplantc.org/>
$ch = curl_init();
$url="${base_url}/token";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$credentials = "${consumer_key}:${consumer_secret}";
curl_setopt($ch, CURLOPT_USERPWD, $credentials);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-type: application/x-www-form-urlencoded'));
$post_params = array(
'grant_type'=>'password',
'username'=>$username,
'password'=>$password,
'scope'=>'PRODUCTION'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
$response = curl_exec($ch);
$resultStatus = curl_getinfo($ch);
Jon Duvick
PlantGDB Manager
http://www.plantgdb.org/
Department of Genetics, Development and Cell Biology
2258 Molecular Biology Building
Iowa State University
Ames IA 50011
(515) 294-2360
(515) 294-6755 FAX
_______________________________________________
Iplant-api-dev Mailing List: Iplant-api-dev at iplantcollaborative.org<mailto:Iplant-api-dev at iplantcollaborative.org>
List Info and Archives: http://mail.iplantcollaborative.org/mailman/listinfo/iplant-api-dev
One-click Unsubscribe: http://mail.iplantcollaborative.org/mailman/options/iplant-api-dev/dooley%40tacc.utexas.edu?unsub=1&unsubconfirm=1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.iplantcollaborative.org/pipermail/iplant-api-dev/attachments/20150107/bc3ac872/attachment-0001.html
More information about the Iplant-api-dev
mailing list