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
557 stars 109 forks source link

data.text empty #16

Closed stjhimy closed 13 years ago

stjhimy commented 13 years ago

Hi there, if i'm posting this in the wrong place please forgive me.

I'm working with jsOAuth, trying to retrieve some data from twitter:

      var oauth = OAuth({
          enablePrivilege: true,
          consumerKey: "",
          consumerSecret: "",
          accessTokenKey: "",
          accessTokenSecret:""
      });

     oauth.get("http://api.twitter.com/1/statuses/home_timeline.json", success, failure); 

I'm getting a 200 OK status in the request but the data.text retrieved is empty. Any idea?

Thanks!

bytespider commented 13 years ago

Hi,

Could you check that http is the correct protocol for twitter? I had the same problem, in that jsOAuth doesnt handle 302 redirects very well.

I found using https to work.

lukaszkorecki commented 13 years ago

It looks like this bit of code will need rethinking.

I'm not sure myself how to treat 30x status codes - behaviour isn't consistent across APIs. Some of them give empty response, some just throw HTML (ignoring Accept headers and such).

bytespider commented 13 years ago

I did some tests trying to abort the redirect, however in chrome, the status never went to 302. This leads me to think that at least in chrome, the 302 is swallowed.

lukaszkorecki commented 13 years ago

Oh boy... It will depend how the browser treats 302 - if it's treated as "permanent" redirect, it will ignore it and take you directly to final location ignoring any interstitial urls. (at least that's how I understand it).

Why (and where) they are redirecting anyway?

I only had this problem with one API before - when a request failed, instead of responding with 503 (or similar), the service's load balancer would redirect you to a totally different page on a different server.

In theory debugging this with something like PhantomJS would work, since it doesn't have a "memory" of previously visited urls and their response codes.

bytespider commented 13 years ago

In my case i was using http:// and not https://, twitter attempts to redirect you to the https version, therefore invalidating the signature. Part of the signature base string is the url.

I was hoping to catch the 302, Abort the request, resign and resend... but nope you cant do that.

So far i see this affecting Chrome and Titanium, I expect this will be across the board.

stjhimy commented 13 years ago

I tried with https:// too, not working, same stuff, 200 OK status and a blank data.text :(

bytespider commented 13 years ago

I notice you have enablePrivilege: true,. I assume you're testing on firefox?

stjhimy commented 13 years ago

Yes firefox

bytespider commented 13 years ago

Could you try the jsOAuth boiler plate? Plumb in your details and make sure you set enablePrivilege: true and customise the getSomeData function

stjhimy commented 13 years ago

Right i'm trying here, but the authorize window that opens is probably missing some params, the window url is https://api.twitter.com/oauth/authorize? and twitter are throwing :

Woah there!

This page requires some information that was not provided. Please return to the site that sent you to this page and try again … it was probably an honest mistake.

stjhimy commented 13 years ago

Even the request_token is returning data.text blank so when it redirects to the authorize url it goes with no params, because there's not a request_token.

bytespider commented 13 years ago

Jhimy,

I think you're using FF5? I also have this issue , but not in FF 3.6.19.

I'm guessing the little hack I use doen't work any more. Namely:

netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead UniversalBrowserWrite');

and

signed.applets.codebase_principal_support

in about:config

I'd switch to chrome if you can. Could you test in FF 3.6 and confirm?

stjhimy commented 13 years ago

Yes i was using FF5. I wish i could switch to chrome too, but this line is not working :

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security --allow-file-access-from-files --allow-file-access spec/runner.html

I'm getting

[0714/110048:INFO:breakpad_mac.mm(89)] Breakpad disabled [1635:2307:10523161222729:ERROR:process_singleton_mac.cc(102)] Unable to obtain profile lock.

This line should be run with sudo permissions ?

bytespider commented 13 years ago

I use a separate profile so I can run multiple instances of chrome . Try something like:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security --allow-file-access-from-files --allow-file-access --user-data-dir=./chrome/ spec/index.html

where --user-data-dir is the directory where you want to store the profile data and spec/index.html is the path to the file you wish to load

stjhimy commented 13 years ago

Oh, it's working now : ) Thanks for all the help, you should insert in your readme "do not work in FF5" : )

bytespider commented 13 years ago

Already ahead of you. :) Glad to get things working for you.

robisaks commented 13 years ago

For anyone using ubuntu, you can use chrome in this way

/opt/google/chrome/google-chrome --disable-web-security --allow-file-access-from-files --allow-file-access --user-data-dir=./chrome/ /path/to/html/file.html

you will want to change /path/to/html/file.html.

If you want to create a shortcut to make things easier, add to panel, choose custom application launcher and use the following command:

/opt/google/chrome/google-chrome --disable-web-security --allow-file-access-from-files --allow-file-access --user-data-dir=./chrome/ %U

now, if you want to open an html file, just drag and drop it onto the shortcut.

krazyjakee commented 12 years ago

1 Uncaught ReferenceError: netscape is not defined

Chrome for Mac.

bytespider commented 12 years ago

On chrome don't use enablePrivilege. This is for firefox 3 only. As documented