node-oauth icon indicating copy to clipboard operation
node-oauth copied to clipboard

OAuth2 for twitter don't work

Open popomore opened this issue 12 years ago • 7 comments

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

popomore avatar May 26 '13 15:05 popomore

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.

qur2 avatar Jun 12 '13 13:06 qur2

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

ciaranj avatar Jun 12 '13 13:06 ciaranj

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.

qur2 avatar Jun 12 '13 13:06 qur2

@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 :)

ciaranj avatar Jun 12 '13 14:06 ciaranj

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:

qur2 avatar Jun 12 '13 15:06 qur2

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}]}' }

sebinsua avatar Sep 08 '13 15:09 sebinsua

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

sebilasse avatar May 24 '16 07:05 sebilasse