firebase / firebase/firebase-tools

Firebase Auth Emulator doesn't work with TOTP MFA secret generation

Open
#6,224 18 comments 23 reactions 0 assignees View on GitHub
emulators: auth type: bug
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

### [REQUIRED] Environment info

**firebase-tools:** 12.4.7

**Platform:** Ubuntu 22.04.2 LTS (WSL)

### [REQUIRED] Test case

Assume a button that generates a secret in any web app and calls the below function when clicked:

```js
const handleMFEnable = async () => {
try {
await reauthenticateWithPopup(user, authGoogleProvider);
const mfSession = await multiFactor(user).getSession();
const mfSecret = await TotpMultiFactorGenerator.generateSecret(mfSession);
const mfUri = await mfSecret.generateQrCodeUrl(user.email, "Test App");
console.log(mfUri);
} catch (error) {
console.error(error);
}
}
```

### [REQUIRED] Steps to reproduce

Running everything exactly as the docs describe:
+ Enabling Auth with Identity Platform
+ Enabling TOTP MFA using the REST API
+ Reauthenticating the User
+ Generating TOTP secret

### [REQUIRED] Expected behavior

It should print the the secret URI in order to display the QR for the user to scan. This operating should be the identical whether auth is emulated or live.

### [REQUIRED] Actual behavior

When running under the Auth emulator, the following error appears client-side:

```
FirebaseError: Firebase: ((Missing phoneEnrollmentInfo.)) (auth/invalid-argument).
at _errorWithCustomMessage (assert.ts:100:18)
at _performFetchWithErrorHandling (index.ts:193:15)
at async TotpMultiFactorGenerator.generateSecret (totp.ts:97:22)
at async handleMFEnable (Account.tsx?t=1691256036484:146:24)
```

However, when disabling the Auth emulator and running everything with the live service, everything works as expected.

Reference [Add TOTP multi-factor authentication to your web app](https://firebase.google.com/docs/auth/web/totp-mfa)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.