-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathyubikey-otp-rule.js
76 lines (66 loc) · 2.26 KB
/
yubikey-otp-rule.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
75
76
function (user, context, callback) {
console.log(auth0);
if(context.clientID === 'client_id' && context.connection === 'name of your connection')
{
var timeDiff = 14 * 24 * 60 * 60 * 1000;
var _ = require('lodash');
var config = {
AUDIENCE: 'yubikeyOTPWithSelfRegistration',
TOKEN_SIGNING_SECRET: configuration.YBMFA_TOKEN_SIGNING_SECRET,
ISSUER: auth0.domain,
WT_URL: configuration.YBMFA_WT_URL
};
var token;
//Returning from OTP validation
if (context.protocol === 'redirect-callback') {
verifyToken(
config.AUDIENCE,
config.TOKEN_SIGNING_SECRET,
config.ISSUER,
context.request.query.token,
postVerify
);
} else {
token = createToken(
config.AUDIENCE,
config.TOKEN_SIGNING_SECRET,
config.ISSUER, {
sub: user.user_id,
email: user.email
}
);
context.redirect = {
url: config.WT_URL + '?token=' + token
};
return callback(null, user, context);
}
}
else return callback(null, user, context);
function createToken(audience, signingSecret, issuer, user) {
var options = {
expiresInMinutes: 10,
audience: audience,
issuer: issuer
};
return jwt.sign(user, new Buffer(signingSecret, "base64"), options);
}
function verifyToken(audience, signingSecret, issuer, token, cb) {
console.log(token);
jwt.verify(
token,
new Buffer(signingSecret, "base64"), {
audience: audience,
issuer: issuer
},
cb
);
}
function postVerify(err, decoded) {
if (err) {
console.log(err);
return callback(new UnauthorizedError("MFA failed"));
} else {
return callback(null, user, context);
}
}
}