@@ -1068,6 +1068,7 @@ function handleMultiFactorSignIn(resolver) {
1068
1068
) ;
1069
1069
// Hide phone form (other second factor types could be supported).
1070
1070
$ ( '#multi-factor-phone' ) . addClass ( 'hidden' ) ;
1071
+ $ ( '#multi-factor-totp' ) . addClass ( 'hidden' ) ;
1071
1072
// Show second factor recovery dialog.
1072
1073
$ ( '#multiFactorModal' ) . modal ( ) ;
1073
1074
}
@@ -1134,6 +1135,7 @@ function onSelectMultiFactorHint(index) {
1134
1135
// Hide all forms for handling each type of second factors.
1135
1136
// Currently only phone is supported.
1136
1137
$ ( '#multi-factor-phone' ) . addClass ( 'hidden' ) ;
1138
+ $ ( '#multi-factor-totp' ) . addClass ( 'hidden' ) ;
1137
1139
if (
1138
1140
! multiFactorErrorResolver ||
1139
1141
typeof multiFactorErrorResolver . hints [ index ] === 'undefined'
@@ -1153,7 +1155,16 @@ function onSelectMultiFactorHint(index) {
1153
1155
// Clear all input.
1154
1156
$ ( '#multi-factor-sign-in-verification-id' ) . val ( '' ) ;
1155
1157
$ ( '#multi-factor-sign-in-verification-code' ) . val ( '' ) ;
1156
- } else {
1158
+ } else if ( multiFactorErrorResolver . hints [ index ] . factorId === 'totp' ) {
1159
+ // Save selected second factor.
1160
+ selectedMultiFactorHint = multiFactorErrorResolver . hints [ index ] ;
1161
+
1162
+ // Show sign-in with totp second factor menu.
1163
+ $ ( '#multi-factor-totp' ) . removeClass ( 'hidden' ) ;
1164
+ // Clear all input.
1165
+ $ ( '#multi-factor-totp-sign-in-verification-code' ) . val ( '' ) ;
1166
+ }
1167
+ else {
1157
1168
// 2nd factor not found or not supported by app.
1158
1169
alertError ( 'Selected 2nd factor is not supported!' ) ;
1159
1170
}
@@ -1207,6 +1218,25 @@ function onFinalizeSignInWithPhoneMultiFactor(event) {
1207
1218
} , onAuthError ) ;
1208
1219
}
1209
1220
1221
+ /**
1222
+ * Completes sign-in with the 2nd factor totp assertion.
1223
+ * @param {!jQuery.Event } event The jQuery event object.
1224
+ */
1225
+ function onFinalizeSignInWithTotpMultiFactor ( event ) {
1226
+ event . preventDefault ( ) ;
1227
+ // Make sure a second factor is selected.
1228
+ const otp = $ ( '#multi-factor-totp-sign-in-verification-code' ) . val ( ) ;
1229
+ if ( ! otp || ! selectedMultiFactorHint || ! multiFactorErrorResolver ) {
1230
+ return ;
1231
+ }
1232
+
1233
+ const assertion = TotpMultiFactorGenerator . assertionForSignIn ( selectedMultiFactorHint . uid , otp )
1234
+ multiFactorErrorResolver . resolveSignIn ( assertion ) . then ( userCredential => {
1235
+ onAuthUserCredentialSuccess ( userCredential ) ;
1236
+ $ ( '#multiFactorModal' ) . modal ( 'hide' ) ;
1237
+ } , onAuthError )
1238
+ }
1239
+
1210
1240
/**
1211
1241
* Adds a new row to insert an OAuth custom parameter key/value pair.
1212
1242
* @param {!jQuery.Event } _event The jQuery event object.
@@ -1336,7 +1366,6 @@ function signInWithPopupRedirect(provider) {
1336
1366
customParameters [ key ] = value ;
1337
1367
}
1338
1368
} ) ;
1339
- console . log ( 'customParameters: ' , customParameters ) ;
1340
1369
// For older jscore versions that do not support this.
1341
1370
if ( provider . setCustomParameters ) {
1342
1371
// Set custom parameters on current provider.
@@ -1985,6 +2014,14 @@ function initApp() {
1985
2014
$ ( '#sign-in-with-phone-multi-factor' ) . click (
1986
2015
onFinalizeSignInWithPhoneMultiFactor
1987
2016
) ;
2017
+
2018
+
2019
+ // Completes multi-factor sign-in with supplied SMS code.
2020
+ $ ( '#sign-in-with-totp-multi-factor' ) . click (
2021
+ onFinalizeSignInWithTotpMultiFactor
2022
+ ) ;
2023
+
2024
+
1988
2025
// Starts multi-factor enrollment with phone number.
1989
2026
$ ( '#enroll-mfa-verify-phone-number' ) . click ( onStartEnrollWithPhoneMultiFactor ) ;
1990
2027
// Completes multi-factor enrollment with supplied SMS code.
0 commit comments