chrisenytc / twitter-pin-auth

A api wrapper to authenticate with twitter using the PIN-based authorization method
MIT License
8 stars 2 forks source link

Always returns [Error: The PIN number you have entered is incorrect!] #2

Open dzeitman opened 9 years ago

dzeitman commented 9 years ago

Steps to reproduce:

Set up new twitter app in admin console - get keys

var TwitterPinAuth = require('twitter-pin-auth'); var twitterPinAuth = new TwitterPinAuth('', '');

twitterPinAuth.requestAuthUrl() .then(function(url) { console.log(url);
}).catch(function(err) { console.error(err); });

Responds with a url like this: https://twitter.com/oauth/authorize?oauth_token=uhZz6wAAAAAAibonAAABUL78Rb0

Open in a browser and see pin: 0056956 // like this re-run script calling authorize with the pin:

twitterPinAuth.authorize(0056956, function(err, data) { if(err) { return console.error(err); } console.log(data.accessTokenKey);
console.log(data.accessTokenSecret);
});

It only returns an error.

[Error: The PIN number you have entered is incorrect!]

Thoughts?

n1k0 commented 8 years ago

Try entering a string instead of a number:

twitterPinAuth.authorize("0056956", ...
dzeitman commented 8 years ago

Same errors: I've tried it as both number and a string value. [Error: The PIN number you have entered is incorrect!]

dzeitman commented 8 years ago

Steps to reproduce:

  1. Auth; var twitterPinAuth = new TwitterPinAuth('KEY', 'SECRET');
  2. GET PIN URL:

twitterPinAuth.requestAuthUrl() .then(function(url) { console.log(url); /// Copy this into a browser and accept and copy the PIN. }).catch(function(err) { console.error(err); });

3: Run Script again and "authorize" using the PIN (as String or Number - either fails)

twitterPinAuth.authorize('PIN NUMBER HERE') .then(function(data) { console.log(data.accessTokenKey); console.log(data.accessTokenSecret); }).catch(function(err) { console.error(err); });

dzeitman commented 8 years ago

UPDATE- Not clear why, but seems you can't re-run the script for step 3 - it must be done in same login sequence / script.

Workaround :
Added prompt lib. npm install prompt

var prompt = require('prompt');

  1. Auth
  2. Open browser and go to url and auth app.

then before step 3: Add: prompt.start();

prompt.get(['pin'], function (err, result) { if (err) { return onErr(err); } console.log('Command-line input received:'); console.log(' PIN: ' + result.pin);

twitterPinAuth.authorize(result.pin)
.then(function(data) {
    console.log(data.accessTokenKey);  
    console.log(data.accessTokenSecret); 
}).catch(function(err) {
    console.error(err);
});

});

function onErr(err) { console.log(err); return 1; }

Prompt will display a prompt in the terminal for a PIN - copy the pin number into terminal and hit enter.

Function will then return tokens as expected.