Pregunta

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"})>
¿Fue útil?

Solución

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!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top