ciaranj / node-oauth

OAuth wrapper for node.js
MIT License
2.44k stars 662 forks source link

OAuth2 for twitter don't work #143

Open popomore opened 11 years ago

popomore commented 11 years ago
var twitterConsumerKey = '';
var twitterConsumerSecret = '';

var OAuth2 = require('oauth').OAuth2;
var oauth2 = new OAuth2(
  twitterConsumerKey,
  twitterConsumerSecret,
  'https://api.twitter.com/',
  null,
  'oauth2/token',
  null
);
oauth2.getOAuthAccessToken(
  '',
  {'grant_type':'client_credentials'},
  function (e, access_token, refresh_token, results){
     console.log('bearer: ',access_token);
  }
);

access_token return undefined

qur2 commented 11 years ago

Well, if you look at the first param, there is an error:

{ '0':
   { statusCode: 403,
     data: '{"errors":[{"code":99,"label":"authenticity_token_error","message":"Unable to verify your credentials"}]}' } }
bearer:  undefined

I'm trying to do the same, but it seems that OAuth2 puts the params such has grant_type in the request body rather than the headers.

ciaranj commented 11 years ago

And you're sure this is nothing to do with: https://dev.twitter.com/blog/api-v1-is-retired ?

qur2 commented 11 years ago

Oh yes, it has, definitely. Personally I was still on wild query to get my timeline, no auth at all. So now I have to implement that and I thought my use case needs this app-only auth. This issue was recent and I thought I'd expose my findings. I would make a pull request for that, but the problem is that it's twitter specific, isn't it? Right now I'm inspecting possible solutions with passportjs and passport-twitter.

ciaranj commented 11 years ago

@qur2 I'm not too sure, but it certainly looks as though its an issue with your specific configuration rather than the actual library itself :)

qur2 commented 11 years ago

I'm not even sure it's the library to use for those twitter application-only requests. I'm trying to achieve the same as the bug reporter and saw that there was an error. So his problem is not the undefined value but rather the fact that authentication fails.

Right now I'm digging on passportjs side as I already rely on it. If it's just for me, you can close the bug, I won't miss it :hammer:

sebinsua commented 11 years ago

Yeah, this doesn't work. I was trying to use Oauth2.get() in the way shown on this site: http://webapplog.com/node-js-oauth1-0-and-oauth2-0-twitter-api-v1-1-examples/

The solution was just to make a normal HTTP request, like so: https://gist.github.com/Dakuan/5899971

Otherwise I was getting this: { statusCode: 400, data: '{"errors":[{"message":"Bad Authentication data","code":215}]}' }

sebilasse commented 8 years ago

You could also override the prototype of .getOAuthAccessToken() – see http://stackoverflow.com/questions/33222724/how-to-properly-use-passport-oauth2-for-using-twitter-oauth2-auth-service/37399503#37399503