@@ -7,110 +7,130 @@ var stdIn = process.openStdin();
7
7
8
8
var awaiter = null ;
9
9
10
- stdIn . addListener ( "data" , function ( d ) {
10
+ stdIn . addListener ( "data" , function ( d ) {
11
11
var content = d . toString ( ) . trim ( ) ;
12
-
13
- if ( awaiter )
14
- {
12
+
13
+ if ( awaiter ) {
15
14
var _awaiter = awaiter ;
16
15
awaiter = null ;
17
16
_awaiter ( content ) ;
18
17
}
19
18
} ) ;
20
19
21
20
var handleBasicAuthentication = function ( onSuccess , onRequiresTwoFa , onFailure ) {
22
-
23
21
var username = null ;
24
22
var password = null ;
25
23
26
- var withPassword = function ( input ) {
24
+ var withPassword = function ( input ) {
27
25
password = input ;
26
+
27
+ var octokit = octokitWrapper . createOctokit ( ) ;
28
+
29
+ octokit . authenticate ( {
30
+ type : "basic" ,
31
+ username : username ,
32
+ password : password
33
+ } ) ;
34
+
35
+ octokit . authorization . create ( {
36
+ scopes : scopes ,
37
+ note : config . appName ,
38
+ client_id : config . clientId ,
39
+ client_secret : config . clientSecret
40
+ } , function ( err , res ) {
41
+ if ( err ) {
42
+ if ( err . message === '{"message":"Must specify two-factor authentication OTP code.","documentation_url":"https://developer.github.com/v3/auth#working-with-two-factor-authentication"}' ) {
43
+ onRequiresTwoFa ( ) ;
44
+ return ;
45
+ }
46
+ else {
47
+ onFailure ( err )
48
+ }
49
+ }
50
+ else {
51
+ onSuccess ( res . data . token ) ;
52
+ }
53
+ } ) ;
28
54
}
29
55
30
- var promptPassword = function ( ) {
56
+ var promptPassword = function ( ) {
57
+ process . stdout . write ( "Password: " ) ;
31
58
awaiter = withPassword ;
32
59
}
33
60
34
- var withUser = function ( input ) {
61
+ var withUser = function ( input ) {
35
62
username = input ;
36
63
promptPassword ( ) ;
37
64
}
38
65
39
- var promptUser = function ( ) {
66
+ var promptUser = function ( ) {
67
+ process . stdout . write ( "Username: " ) ;
40
68
awaiter = withUser ;
41
69
}
42
70
43
71
promptUser ( ) ;
44
-
45
-
46
- // var user = readlineSync.question('User: ');
47
-
48
- // var pwd = readlineSync.question('Password: ', {
49
- // hideEchoBack: true
50
- // });
51
-
52
- // var octokit = octokitWrapper.createOctokit();
53
-
54
- // octokit.authenticate({
55
- // type: "basic",
56
- // username: user,
57
- // password: pwd
58
- // });
59
-
60
- // octokit.authorization.create({
61
- // scopes: scopes,
62
- // note: config.appName,
63
- // client_id: config.clientId,
64
- // client_secret: config.clientSecret
65
- // }, function (err, res) {
66
- // if (err) {
67
- // if (err.message === '{"message":"Must specify two-factor authentication OTP code.","documentation_url":"https://developer.github.com/v3/auth#working-with-two-factor-authentication"}') {
68
- // onRequiresTwoFa();
69
- // return;
70
- // }
71
- // else {
72
- // onFailure(err)
73
- // }
74
- // }
75
- // else {
76
- // onSuccess(res.data.token);
77
- // }
78
- // });
79
72
}
80
73
81
74
var handleTwoFactorAuthentication = function ( onSuccess , onFailure ) {
82
- var user = readlineSync . question ( 'User: ' ) ;
83
-
84
- var pwd = readlineSync . question ( 'Password: ' , {
85
- hideEchoBack : true
86
- } ) ;
87
-
88
- var twofa = readlineSync . question ( 'TwoFactor: ' ) ;
89
-
90
- var octokit = octokitWrapper . createOctokit ( ) ;
91
-
92
- octokit . authenticate ( {
93
- type : "basic" ,
94
- username : user ,
95
- password : pwd
96
- } ) ;
97
-
98
- octokit . authorization . create ( {
99
- scopes : scopes ,
100
- note : config . appName ,
101
- client_id : config . clientId ,
102
- client_secret : config . clientSecret ,
103
- headers : {
104
- "X-GitHub-OTP" : twofa
105
- }
106
- } , function ( err , res ) {
107
- if ( err ) {
108
- onFailure ( err )
109
- }
110
- else {
111
- onSuccess ( res . data . token ) ;
112
- }
113
- } ) ;
75
+ var username = null ;
76
+ var password = null ;
77
+ var twoFactor = null ;
78
+
79
+ var withTwoFactor = function ( input ) {
80
+ twoFactor = input ;
81
+
82
+ var octokit = octokitWrapper . createOctokit ( ) ;
83
+
84
+ octokit . authenticate ( {
85
+ type : "basic" ,
86
+ username : username ,
87
+ password : password
88
+ } ) ;
89
+
90
+ octokit . authorization . create ( {
91
+ scopes : scopes ,
92
+ note : config . appName ,
93
+ client_id : config . clientId ,
94
+ client_secret : config . clientSecret ,
95
+ headers : {
96
+ "X-GitHub-OTP" : twoFactor
97
+ }
98
+ } , function ( err , res ) {
99
+ if ( err ) {
100
+ onFailure ( err )
101
+ }
102
+ else {
103
+ onSuccess ( res . data . token ) ;
104
+ }
105
+ } ) ;
106
+ }
107
+
108
+ var promptTwoFactor = function ( ) {
109
+ process . stdout . write ( "Two Factor: " ) ;
110
+ awaiter = withTwoFactor ;
111
+ }
112
+
113
+ var withPassword = function ( input ) {
114
+ password = input ;
115
+ promptTwoFactor ( ) ;
116
+ }
117
+
118
+ var promptPassword = function ( ) {
119
+ process . stdout . write ( "Password: " ) ;
120
+ awaiter = withPassword ;
121
+ }
122
+
123
+ var withUser = function ( input ) {
124
+ username = input ;
125
+ promptPassword ( ) ;
126
+ }
127
+
128
+ var promptUser = function ( ) {
129
+ process . stdout . write ( "Username: " ) ;
130
+ awaiter = withUser ;
131
+ }
132
+
133
+ promptUser ( ) ;
114
134
}
115
135
116
136
module . exports = {
0 commit comments