-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwoFactorAuth.js
44 lines (37 loc) · 1.2 KB
/
twoFactorAuth.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
module.exports = {
// accountSid: sid from cred.js used for twilio api
// authToken: token from cred.js used for twilio api
// twilio: twilio module passed in from main app
// speakeasy: speakeasy 2factorauth module passed in from main app
startAuth: function(accountSid, authToken, twilio, speakeasy, phone) {
var client = twilio(accountSid, authToken);
var secret = speakeasy.generateSecret({length: 20});
var token = speakeasy.hotp({
secret: secret.base32,
encoding: 'base32',
counter: 123
});
client.sendMessage({
body: token,
to: phone.toString(),
from: "+18053035298"
});
console.log(token);
console.log(secret);
return secret;
},
authenticateToken: function(speakeasy, token, secret) {
console.log("---------");
console.log(token);
console.log(secret);
console.log("---------");
var verified = speakeasy.hotp.verify({
secret: secret.base32,
encoding: 'base32',
token: token,
counter: 123
});
console.log(verified);
return verified;
}
};