/
validate.js
74 lines (53 loc) · 1.39 KB
/
validate.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module.exports = {
friendlyName: 'Validate',
description: 'Validates the given code compared to user\'s key.',
extendedDescription: '',
inputs: {
key: {
example: '44xtha1v228542u5q6ddxzdoukji1m74',
description: 'The secret key, which is to be stored with the userdata.',
required: true
},
code: {
example: '123456',
description: 'The code the user entered to be validated.',
required: true
}
},
defaultExit: 'invalid',
exits: {
error: {
description: 'Unexpected error occurred.',
},
valid: {
description: 'Valid code.',
},
invalid: {
description: 'Invalid code.',
},
},
fn: function (inputs,exits) {
var tfa = require('2fa');
var opts = {
// the number of counters to check before what we're given
// default: 0
beforeDrift: 2,
// and the number to check after
// default: 0
afterDrift: 2,
// if before and after drift aren't specified,
// before + after drift are set to drift / 2
// default: 0
drift: 4,
// the step for the TOTP counter in seconds
// default: 30
step: 30
};
// for TOTP, the counter is calculated internally using Date.now();
if(tfa.verifyTOTP(inputs.key, inputs.code, opts)){
return exits.valid();
} else {
return exits.invalid();
}
},
};