I am an oAuth newbie and struggling to implement a simple oAuth consumer in ColdFusion against a PHP site which uses the Pantheon oAuth library. The following curl script works perfectly and returns the JSON I need.
curl -X POST -i -H "Content-type: application/json" -c cookies.txt -X
POST https://example.org/service/user/login?mykeyhere -d
'{"username":"myuser","password":"mypassword"}'
My question is how do i implement this in ColdFusion, returning the responding JSON into a variable that I can parse?
Thanks for your help!
Ben
UPDATE 5/3/13
Ok, I tried to translate the cURL line and am getting closer - here's what I did:
<cfset mydata = serializejson('{"username":"myuser","password":"mypass"}')>
<cfhttp url="https://example.org/service/user/login" method="post" >
<cfhttpparam type="header" name="Content-type" value="application/json" >
<cfhttpparam type="header" name="oauth_consumer_key" value="mykey" >
<cfhttpparam type="body" value='#mydata#' >
<cfhttpparam name="cookies.txt" type="cookie" value="" >
</cfhttp>
However, I am still getting a negative response - but it seems it is because I am not passing the values that are in the "-d" clause from the cURL script correctly. Any ideas?
Thanks again!
Latest update:
Tried both of these to no avail - i also removed the cookie line:
<cfset mydata = '{"username":"myuser","password":"mypass"}'>
<cfset mydata = serializejson('{"username=myuser","password=mypass"}')>
3:20 ET
Sorry - made the correction as per your comment to below - but still no luck:
<cfset myData = serializeJSON({username="user",password="pass"})>
Great idea on the debugging of the cURL post - I figured it out. It was just about the headers - the data WAS being passed correctly.
Once the JSON is created, here's the CFHTTP call:
<cfhttp url="https://mydomain.org/service/user/login?oauth_consumer_key=myKeyHere" method="post" >
<cfhttpparam type="header" name="Content-type" value="application/json" >
<cfhttpparam type="header" name="Accept" value="*/*" >
<cfhttpparam type="body" value="#mydata#" >
</cfhttp>
Works great - thanks to Leigh for helping me think this through!
Related
I'm new to this and not sure if I'm doing this right.
My requirement is to trigger(build) a jenkins job using command-line which I will invoke using ansible.
I'm following the instructions on this stackoverflow link.
I followed the below steps but Unfortunately the build does not get triggered.
Step 1:
I logged in Jenkins portal https://myjenkins.com:9043 using my user id user114 which is also the Jenkins administrator.
I then created API-token for my user id which is 118f32aa48601c136d29y11f3dd0e107f5.
Step 2:
I then selected Trigger Build Remotely option for job5 and gave the token name as 118f32aa48601c136d29y11f3dd0e107f5
Step 3: I then created Jenkins-Crumb using the below command:
`curl -s -k 'https://user114:118f32aa48601c136d29y11f3dd0e107f5#myjenkins.com:9043/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'
Jenkins-Crumb:5196c183ad95cf3c0482873e34236f3b78ab628ecba968086cd19s7430016a4e`
Then i tried the below commands with the intention of triggering the build for job5 but none of them triggered my Jenkins build.
Attemp 1:
$ curl -I -k -X POST https://user114:118f32aa48601c136d29y11f3dd0e107f5#myjenkins.com:9043/job/job5/build -H "Jenkins-Crumb:5196c183ad95cf3c0482873e34236f3b78ab628ecba968086cd19s7430016a4e"
HTTP/1.1 400 Bad Request
X-Content-Type-Options: nosniff
Cache-Control: must-revalidate,no-cache,no-store
Content-Type: text/html;charset=iso-8859-1
Content-Length: 481
Server: Jetty(NOTHING)
Attempt 2:
$ curl -k -X POST https://user114:118f32aa48601c136d29y11f3dd0e107f5#myjenkins.com:9043/job/job5/build -H "Jenkins-Crumb:5196c183ad95cf3c0482873e34236f3b78ab628ecba968086cd19s7430016a4e"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 400 Nothing is submitted</title>
</head>
<body><h2>HTTP ERROR 400 Nothing is submitted</h2>
<table>
<tr><th>URI:</th><td>/job/job5/build</td></tr>
<tr><th>STATUS:</th><td>400</td></tr>
<tr><th>MESSAGE:</th><td>Nothing is submitted</td></tr>
<tr><th>SERVLET:</th><td>Stapler</td></tr>
</table>
<hr>Powered by Jetty:// NOTHING<hr/>
</body>
Attempt 3:
$ curl -k -X POST https://user114:118f32aa48601c136d29y11f3dd0e107f5#myjenkins.com:9043/job/job5/build?token=118f32aa48601c136d29y11f3dd0e107f5 -H "Jenkins-Crumb:5196c183ad95cf3c0482873e34236f3b78ab628ecba968086cd19s7430016a4e"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 400 This page expects a form submission</title>
</head>
<body><h2>HTTP ERROR 400 This page expects a form submission</h2>
<table>
<tr><th>URI:</th><td>/job/job5/build</td></tr>
<tr><th>STATUS:</th><td>400</td></tr>
<tr><th>MESSAGE:</th><td>This page expects a form submission</td></tr>
<tr><th>SERVLET:</th><td>Stapler</td></tr>
</table>
<hr>Powered by Jetty:// NOTHING<hr/>
</body>
</html>
Further, I also intend to pass parameters to this jenkins job which i dont know how-to.
Can you please suggest ?
I started using the Generic Webhook Plugin for this. It takes away a lot of the hassle and allows you to parse any JSON/XML payload as you please.
I currently trying to get the issues from JIRA via REST API via this:
curl -D- -u USERNAME -X GET -H "Content-Type: application/json" \
https://issues.apache.org/jira/rest/api/2/search? jql=project%20%3D%20MNG%20AND%20fixVersion%20%3D%203.4.0 \
-o release.json
But unfortunately i don't get all issues. Only 50 instead of 59. I already checked if all the issues have the correct fixVersion set to 3.4.0.
But via browser:
https://issues.apache.org/jira/issues/?jql=project%20%3D%20MNG%20AND%20fixVersion%20%3D%203.4.0
I got all the issues.
Do i oversight something ? Some idea hint ?
50 is a default value for "maxResults" parameter. Here's API documentation https://docs.atlassian.com/jira/REST/latest/#api/2/search-search
The accept header "Accept: text/plain,text/html;" works for sites like http://nginx.org. However when I run it locally against my Rails 4.1 app
curl -v -H "Accept: text/plain,text/html;" localhost:3000/
on a html responding homepage, I get a 500 error page for an ActionController::UnknownFormat execption.
When I curl
curl -v -H "Accept: text/plain,text/html" localhost:3000
everything works fine (notice the missing ;)
How can I also make it work for Accept: text/plain,text/html; case?
Apparently it's malformed according to RFC 7231 and shouldn't work. nginx.org turns back 200 OK even for obviously malformed MIME types.
See also https://github.com/rails/rails/issues/21749
I'm attempting to gather XML data automatically using curl, and my command so far is
curl -E keyStore.pem -d 'uid=myusername&password=mypassword&active=y&type=F' 'https://www.aidaptest.naimes.faa.gov/aidap/XmlNotamServlet HTTP/1.1/' -k
but it keeps on giving me a "Your browser sent a query this server could not understand." error.
I'm pretty sure that it's connecting since it's not rejecting me, but I don't know how to properly format the POST. Here's some documentation they gave me for the format of the POST request.
POST <URL>/aidap/XmlNotamServlet HTTP/1.1
Content-type: application/x-www-form-urlencoded
Content-length: <input_parameter’s length>
<a blank line>
<input_parameter>`
input_parameter is uid, password, and location_id bit and is correct
Am I doing this correctly from what you can see?
Something like this should do it.
curl -E keyStore.pem -v -X POST -i --header Content-Type:application/x-www-form-urlencoded
-d 'uid=myusername&password=mypassword&active=y&type=F' 'https://www.aidaptest.naimes.faa.gov/aidap/XmlNotamServlet'
I don't think you need HTTP/1.1 at the end of the URL in the command line. And even if you needed it, you certainly don't need the final / character before the closing single quote.
How rails can grab headers of a curl request like:
curl -v -H 'X-Auth-Service-Provider: https://api.twitter.com/1/account/verify_credentials.json' -H 'X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/",
oauth_consumer_key="yTrEIQH6jhtmLUypg8T5", oauth_signature_method="HMAC-SHA1",
oauth_token="514797-YuI8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWTyu",oauth_timestamp="1271323750",
oauth_nonce="oYu6nMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7U9Y",
oauth_version="1.0", oauth_signature="CV4bTfE7Rs9J1kafTGwufLJdspo%3D"' -F "file=#/path/to/file" http://localhost:3000/api/upload.xml
Grab those values: oauth_cosumer, oauth_token, oauth_timestamp etc.
thanks in advance!
headers['oauth_consumer_key']
etc...