-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathokta-mfa.js
More file actions
78 lines (63 loc) · 1.85 KB
/
Copy pathokta-mfa.js
File metadata and controls
78 lines (63 loc) · 1.85 KB
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
77
78
'use strict';
const clui = require('clui');
const OktaHelpers = require('./okta-helpers');
const GoogleAuthenticator = {
name: "GoogleAuthenticator",
detect: function *(nightmare) {
return yield nightmare.visible('.mfa-verify-totp');
},
prompt: function *(ci) {
return yield ci.prompt({
type: 'input',
message: 'Google Authenticator code:'
});
},
verify: function *(mfaPrompt, nightmare) {
const spinner = new clui.Spinner('Verifying MFA...');
spinner.start();
yield nightmare
.visible('.mfa-verify-totp')
.wait(300)
.type('input[name="answer"]', mfaPrompt)
.wait(1000)
.click('input[type="submit"]')
.wait(OktaHelpers.waitAndEmitSAMLResponse);
spinner.stop();
const hasError = yield nightmare
.exists('.o-form-has-errors');
if (hasError) {
let errMsg = yield nightmare.evaluate(function () {
return document.querySelector('.o-form-has-errors').innerText;
});
throw new Error(errMsg);
}
}
};
const OktaVerify = {
name: "OktaVerify",
detect: function *(nightmare) {
return yield nightmare
.wait(500)
.visible('.mfa-verify-push');
},
prompt: function *() {
// None needed - will send a push
},
verify: function *(mfaPrompt, nightmare) {
const spinner = new clui.Spinner('Sending Okta Verify push notification...');
spinner.start();
yield nightmare
.click('.mfa-verify-push input[type="submit"]')
.wait(OktaHelpers.waitAndEmitSAMLResponse);
spinner.stop();
const hasError = yield nightmare
.exists('.o-form-has-errors');
if (hasError) {
let errMsg = yield nightmare.evaluate(function () {
return document.querySelector('.o-form-has-errors').innerText;
});
throw new Error(errMsg);
}
}
};
module.exports = [GoogleAuthenticator, OktaVerify];