Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 76e34d4

Browse files
Removing readline-sync
1 parent 732c521 commit 76e34d4

File tree

2 files changed

+97
-78
lines changed

2 files changed

+97
-78
lines changed

octorun/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"dependencies": {
1313
"commander": "^2.14.1",
1414
"dotenv": "^1.0.0",
15-
"octokit-rest-for-node-v0.12": "1.0.1",
16-
"readline-sync": "^1.4.9"
15+
"octokit-rest-for-node-v0.12": "1.0.1"
1716
}
1817
}

octorun/src/authentication.js

Lines changed: 96 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,110 +7,130 @@ var stdIn = process.openStdin();
77

88
var awaiter = null;
99

10-
stdIn.addListener("data", function(d){
10+
stdIn.addListener("data", function (d) {
1111
var content = d.toString().trim();
12-
13-
if(awaiter)
14-
{
12+
13+
if (awaiter) {
1514
var _awaiter = awaiter;
1615
awaiter = null;
1716
_awaiter(content);
1817
}
1918
});
2019

2120
var handleBasicAuthentication = function (onSuccess, onRequiresTwoFa, onFailure) {
22-
2321
var username = null;
2422
var password = null;
2523

26-
var withPassword = function(input) {
24+
var withPassword = function (input) {
2725
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+
});
2854
}
2955

30-
var promptPassword = function(){
56+
var promptPassword = function () {
57+
process.stdout.write("Password: ");
3158
awaiter = withPassword;
3259
}
3360

34-
var withUser = function(input) {
61+
var withUser = function (input) {
3562
username = input;
3663
promptPassword();
3764
}
3865

39-
var promptUser = function() {
66+
var promptUser = function () {
67+
process.stdout.write("Username: ");
4068
awaiter = withUser;
4169
}
4270

4371
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-
// });
7972
}
8073

8174
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();
114134
}
115135

116136
module.exports = {

0 commit comments

Comments
 (0)