| 83 | import AuthAdapter from './AuthAdapter'; |
| 84 | class MFAAdapter extends AuthAdapter { |
| 85 | validateOptions(opts) { |
| 86 | const validOptions = opts.options; |
| 87 | if (!Array.isArray(validOptions)) { |
| 88 | throw 'mfa.options must be an array'; |
| 89 | } |
| 90 | this.sms = validOptions.includes('SMS'); |
| 91 | this.totp = validOptions.includes('TOTP'); |
| 92 | if (!this.sms && !this.totp) { |
| 93 | throw 'mfa.options must include SMS or TOTP'; |
| 94 | } |
| 95 | const digits = opts.digits || 6; |
| 96 | const period = opts.period || 30; |
| 97 | if (typeof digits !== 'number') { |
| 98 | throw 'mfa.digits must be a number'; |
| 99 | } |
| 100 | if (typeof period !== 'number') { |
| 101 | throw 'mfa.period must be a number'; |
| 102 | } |
| 103 | if (digits < 4 || digits > 10) { |
| 104 | throw 'mfa.digits must be between 4 and 10'; |
| 105 | } |
| 106 | if (period < 10) { |
| 107 | throw 'mfa.period must be greater than 10'; |
| 108 | } |
| 109 | const sendSMS = opts.sendSMS; |
| 110 | if (this.sms && typeof sendSMS !== 'function') { |
| 111 | throw 'mfa.sendSMS callback must be defined when using SMS OTPs'; |
| 112 | } |
| 113 | this.smsCallback = sendSMS; |
| 114 | this.digits = digits; |
| 115 | this.period = period; |
| 116 | this.algorithm = opts.algorithm || 'SHA1'; |
| 117 | } |
| 118 | validateSetUp(mfaData) { |
| 119 | if (mfaData.mobile && this.sms) { |
| 120 | return this.setupMobileOTP(mfaData.mobile); |