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

XML responses #21

Closed mstalfoort closed 12 years ago

mstalfoort commented 13 years ago

I'm testing with this library, which I like, but I' m running into issues whereas the service I'm trying to access sends XML responses to me. Is this library capable of handling XML responses or should this be implemented?

bytespider commented 13 years ago

Hi Marc,

I see no reason why XML should be an issue. the call back returns an object with a text property which you can then send into a XML parser or document fragment if you have a DOM around.

Clearly you'll want to avoid the *JSON methods.

Rob

Rob Griffiths Twitter: @bytespider Github: https://github.com/bytespider

bytespider.euSent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Friday, 23 September 2011 at 15:23, Marc Stalfoort wrote:

I'm testing with this library, which I like, but I' m running into issues whereas the service I'm trying to access sends XML responses to me. Is this library capable of handling XML responses or should this be implemented?

Reply to this email directly or view it on GitHub: https://github.com/bytespider/jsOAuth/issues/21

mstalfoort commented 13 years ago

That would be awesome Can you supply me an example on how I would act on XML responses?

bytespider commented 13 years ago

If you're wanting to work with JSON but the stream is in XML try https://github.com/bytespider/XML2JSON/blob/master/xml2json.js

It may not work with webkit, I've not updated it in a while. I'll try write up an example later today.

mstalfoort commented 13 years ago

Looking forward to your example.

The situation as I have it now is: I'm performing a fetchRequestToken and the response I get is in XML. In this method there is the following line "var token = oauth.parseTokenRequest(data.text);" which doesn't correctly convert the response so the oauth_token && oauth_token_secret properties on this object aren't set properly. Therefor the "oauth.setAccessToken([token.oauth_token, token.oauth_token_secret])" gets rejected eventually from the service I'm connecting to.

I hope this is enough info for you to setup an example.

bytespider commented 13 years ago

Okay this is definitely an area where i'll need to write a patch as currently the code assumes that the response for Token requests is a query string.

Your the first where the response is XML.

bytespider commented 13 years ago

Can you provide example of the response?

mstalfoort commented 13 years ago

this is 1 option:

<?xml version="1.0" encoding="UTF-8"?> < oauth type="request" > < token > udsfiusdf789HJAdsUYUI < / token > < secret > 76er78dyyufbYBFGJH < / secret > < / oauth >

mstalfoort commented 13 years ago

this is another option:

<?xml version="1.0" encoding="UTF-8"?> < oauth type="request" > \t < token > udsfiusdf789HJAdsUYUI < / token > \t < secret > 76er78dyyufbYBFGJH < / secret > < / oauth >

bytespider commented 13 years ago

Hi Marc

Could you try out this version http://cl.ly/AQV5

mstalfoort commented 13 years ago

Hey Rob

I finally managed to get working with the version you setup for me, thanks for that, and at first it wasn't completely working for me so I extended your class to my needs. Still it's a good starting point and if you're interested on what exactly I did to fit it to my needs please let me know. I'm not sending a pull request at the moment because I'm not sure at this point in the extension I did does comply to Oauth spec in XML mode, so I have to check this first.

bytespider commented 13 years ago

Mark, any info on how you used the library is always handy for future development.