@@ -94,6 +94,7 @@ class MFAAdapter extends AuthAdapter {
94
94
}
95
95
const digits = opts . digits || 6 ;
96
96
const period = opts . period || 30 ;
97
+ const emailOTPExpiry = opts . emailOTPExpiry || 5 * 60 ; // Default to 5 minutes
97
98
if ( typeof digits !== 'number' ) {
98
99
throw 'mfa.digits must be a number' ;
99
100
}
@@ -107,8 +108,8 @@ class MFAAdapter extends AuthAdapter {
107
108
throw 'mfa.period must be greater than 10' ;
108
109
}
109
110
if ( this . email ) {
110
- if ( this . emailOTPExpiry < 60 ) {
111
- throw 'mfa.emailExpiry must be greater than 60 seconds ' ;
111
+ if ( this . emailOTPExpiry < 5 * 60 ) {
112
+ throw 'mfa.emailExpiry must be greater than 5 minutes ' ;
112
113
}
113
114
}
114
115
const sendSMS = opts . sendSMS ;
@@ -123,18 +124,19 @@ class MFAAdapter extends AuthAdapter {
123
124
this . emailCallback = sendEmail ;
124
125
this . digits = digits ;
125
126
this . period = period ;
127
+ this . emailOTPExpiry = emailOTPExpiry ;
126
128
this . algorithm = opts . algorithm || 'SHA1' ;
127
129
}
128
130
validateSetUp ( mfaData ) {
129
131
if ( mfaData . mobile && this . sms ) {
130
132
return this . setupMobileOTP ( mfaData . mobile ) ;
131
133
}
132
- if ( this . totp ) {
133
- return this . setupTOTP ( mfaData ) ;
134
- }
135
134
if ( mfaData . email && this . email ) {
136
135
return this . setupEmailOTP ( mfaData . email ) ;
137
136
}
137
+ if ( this . totp ) {
138
+ return this . setupTOTP ( mfaData ) ;
139
+ }
138
140
throw 'Invalid MFA data' ;
139
141
}
140
142
async validateLogin ( loginData , _ , req ) {
@@ -308,15 +310,16 @@ class MFAAdapter extends AuthAdapter {
308
310
}
309
311
310
312
async sendEmail ( email ) {
311
- if ( ! / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / . test ( email ) ) {
312
- throw 'Invalid email address.' ;
313
- }
313
+ const decodedEmail = email . replace ( / _ _ _ D O T _ _ _ / g, '.' )
314
+ if ( ! / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / . test ( decodedEmail ) ) {
315
+ throw 'Invalid email address.' ;
316
+ }
314
317
let token = '' ;
315
318
while ( token . length < this . digits ) {
316
- token += randomString ( 10 ) . replace ( / \D / g, '' ) ;
319
+ token += ( 0 , _cryptoUtils . randomString ) ( 10 ) . replace ( / \D / g, '' ) ;
317
320
}
318
321
token = token . substring ( 0 , this . digits ) ;
319
- await Promise . resolve ( this . emailCallback ( token , email ) ) ;
322
+ await Promise . resolve ( this . emailCallback ( token , decodedEmail ) ) ;
320
323
const expiry = new Date ( new Date ( ) . getTime ( ) + this . emailOTPExpiry * 1000 ) ;
321
324
return { token, expiry } ;
322
325
}
0 commit comments