bytespider / jsOAuth

JavaScript implimentation of the OAuth protocol. Currently supports version 1.0 (RFC5849) of the specification. Node.js & CommonJS compatible.
http://bytespider.github.com/jsOAuth/
MIT License
556 stars 108 forks source link

postJSON - Content-Type: 'application/json' #26

Closed ericktai closed 12 years ago

ericktai commented 12 years ago

Hi Rob,

I thought about other things that people ran into and thought of this recent support ticket. Again, great job on this library, it's helped people get up and running with JS and OAuth really quickly. Well written GitHub docs by the way. I was able to get my example running in < 10 minutes while watching TV :)

The users are basically sending/retrieving JSON through a REST API. Somebody was trying to use OAuth.postJSON to send up some JSON but it wasn't working for him. I think it's because StackMob expects the header 'Content-Type': 'application/json'. postJSON seems to call OAuth.post which in turn doesn't set that header.

I hence had him do this, since it looked like the postJSON was a convenience wrapper to stringify the json object.

oauth.request( { method : 'POST', headers: { 'Content-Type': 'application/json' }, url : ..., //your url data: JSON.stringify(yourobject), //it looks like postJSON is simply a convenience wrapper that converts your object to a string via JSON.stringify success: function(data) { console.debug(data); }, //again, using chrome console to view output failure: function(data) { console.error('fail'); console.debug(data); } });

Would you be able to punch a hole into post/postJSON to pass in headers - and/or should the headers for postJSON have "application/json" by default?

Erick

bytespider commented 12 years ago

Erick, thinking about this, you are right. Given that we are sending json the header should be set appropriately. Ill look at patching this now

ericktai commented 12 years ago

Awesome. Thanks Rob!

bytespider commented 12 years ago

Erick, could you give this version ago and let me know if it works for you? http://cl.ly/BqSL

I really need to write a better test suite for v2

ericktai commented 12 years ago

Works!

Sorry for not getting back to you earlier - got swept up in a project

On Tue, Nov 15, 2011 at 1:27 PM, Rob Griffiths < reply@reply.github.com

wrote:

Erick, could you give this version ago and let me know if it works for you? http://cl.ly/BqSL

I really need to write a better test suite for v2


Reply to this email directly or view it on GitHub: https://github.com/bytespider/jsOAuth/issues/26#issuecomment-2751598