-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_pinauth.js
56 lines (47 loc) · 1.75 KB
/
app_pinauth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var tokens = {
consumer_key: '',
consumer_secret: ''
};
var fs = require('fs');
var open = require('open');
var OAuth = require('oauth').OAuth;
var request = require('request');
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var oauth = new OAuth(
"https://api.twitter.com/oauth/request_token",
"https://api.twitter.com/oauth/access_token",
tokens.consumer_key,
tokens.consumer_secret,
"1.0",
'oob',
"HMAC-SHA1"
);
oauth.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results){
console.log(error, oauth_token, oauth_token_secret, results);
if(error){
console.log('error during step #1', error);
process.exit();
return;
}
var requestParams = 'oauth_token='+oauth_token+'&oauth_token_secret='+oauth_token_secret+'&oauth_callback_confirmed='+results.oauth_callback_confirmed;
var url = 'https://twitter.com/oauth/authorize?'+requestParams;
console.log('Opening your browser to '+url);
open(url);
rl.question('Please auth then authorize the app control, then enter the PIN code given by Twitter : ', function(answer){
oauth.getOAuthAccessToken(oauth_token, oauth_token_secret, answer, function(error, oauth_access_token, oauth_access_token_secret, results2) {
console.log('oauth_access_token :' + oauth_access_token);
console.log('oauth_token_secret :' + oauth_access_token_secret);
console.log('accesstoken results :', (results2));
tokens.access_token_key = oauth_access_token;
tokens.access_token_secret = oauth_access_token_secret;
fs.writeFile('tokens.json', JSON.stringify(tokens), function(){
console.log("Tokens saved to tokens.json");
process.exit();
});
});
});
});