-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Open
Labels
Needs AttentionThis issue needs maintainer attention.This issue needs maintainer attention.platform: androidIssues / PRs which are specifically for Android.Issues / PRs which are specifically for Android.platform: iosIssues / PRs which are specifically for iOS.Issues / PRs which are specifically for iOS.plugin: authtype: bugSomething isn't workingSomething isn't working
Description
Is there an existing issue for this?
- I have searched the existing issues.To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Which plugins are affected?
Auth
Which platforms are affected?
Android, iOS
Description
We have enabled the TOTP MFA in our project. The main issue I faced was the mismatch between the error representation on Android and iOS platforms produced by the same test case.
The cases we want to cover are:
- Invalid TOTP code. The user has entered the wrong code from the authenticator app.
- Android: an exception is thrown
invalid-verification-code
code - iOS: an exception is thrown with
resolve-signin-failed
code andThe multifactor verification code used to create the auth credential is invalid. Re-collect the verification code and be sure to use the verification code provided by the user.
message
- TOTP session timeout. User stayed too long on the 2FA verification page before submitting the code.
- Android: an exception is thrown with
unknown
error code andAn internal error has occurred. [TOTP_CHALLENGE_TIMEOUT:TOTP challenge timeout, provide first factor again.]
message. - iOS: an exception is thrown with
resolve-signin-failed
andAn internal error has occurred, print and inspect the error details for more information.
message.
- The number of attempts is exceeded. When the exceeded the maximum allowed number of the retries.
- Android: an exception is thrown with
too-many-requests
code - iOS: an exception is thrown with
resolve-signin-failed
code andExceeded quota.
message
It feels really bad to have different behaviours among the platforms if it's related to the same functionality. It would be great to map the error codes for 2FA from the native implementations and have them documented it as for iOS link
Reproduces on:
firebase_auth: ^5.1.2
firebase_core: ^3.2.0
Reproducing the issue
Firebase auth wrapper:
***
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
// MultiFactorResolver that was provided from the most recent auth attempt but failed on 2FA exception from Firebase
MultiFactorResolver? _resolver;
***
Future<User?> signInWithEmailAndPassword(
String email,
String password,
) async {
try {
final result = await firebaseAuth.signInWithEmailAndPassword(
email: email,
password: password,
);
final user = result.user;
return user;
} on FirebaseAuthMultiFactorException catch (e) {
_resolver = e.resolver;
rethrow;
}
}
***
// Resolve the 2FA sign in
Future<User?> resolveTFASignIn(String code) async {
final resolver = _resolver;
if (resolver == null) {
throw Exception('No recent authentication attempts detected');
}
// Currently we support only 2FA with TOTP
// Check for hints.factorId in case more than one factor is supported
final enrollmentId = resolver.hints.first.uid;
final assertion = await TotpMultiFactorGenerator.getAssertionForSignIn(
enrollmentId,
code,
);
final resultCredentials = await resolver.resolveSignIn(assertion);
final user = resultCredentials.user;
return user;
}
Use the wrapper:
Future<core.User> verifyTFACode({required String code}) async {
try {
final firebaseUser = await firebaseAuthWrapper.resolveTFASignIn(code);
return firebaseUser.toUser;
} on firebase.FirebaseAuthException catch (e) {
print(e);
}
Firebase Core version
3.2.0
Flutter Version
3.22.3
Relevant Log Output
Flutter dependencies
Expand Flutter dependencies
snippet
Replace this line with the contents of your `flutter pub deps -- --style=compact`.
Additional context and comments
No response
MDias04 and cbenhagen
Metadata
Metadata
Assignees
Labels
Needs AttentionThis issue needs maintainer attention.This issue needs maintainer attention.platform: androidIssues / PRs which are specifically for Android.Issues / PRs which are specifically for Android.platform: iosIssues / PRs which are specifically for iOS.Issues / PRs which are specifically for iOS.plugin: authtype: bugSomething isn't workingSomething isn't working
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
SelaseKay commentedon Apr 2, 2025
Hi @IshchikGL, could you update your FlutterFire plugins and check if the issue still persists?
IshchikGL commentedon Apr 6, 2025
@SelaseKay sorry for the late response
So I upgraded to
firebase_core: ^3.13.0
andfirebase_auth: ^5.5.2
.Flutter pub deps
output:Exception codes:
invalid-verification-code
with messageThe verification code from SMS/TOTP is invalid. Please check and enter the correct verification code again.
resolve-signin-failed
with messageThe multifactor verification code used to create the auth credential is invalid. Re-collect the verification code and be sure to use the verification code provided by the user.
unknown
with message:An internal error has occurred. [ TOTP_CHALLENGE_TIMEOUT:TOTP challenge timeout, provide first factor again.
resolve-signin-failed
with messageAn internal error has occurred, print and inspect the error details for more information.
too-many-requests
with messageWe have blocked all requests from this device due to unusual activity. Try again later.
resolve-signin-failed
with messageExceeded quota.
Looks like the issue still persists
SelaseKay commentedon Apr 25, 2025
Hi @IshchikGL, thanks for the additional feedback. After further investigation, I've noticed some few things. While we aim to throw native error codes, the behavior can vary across platforms, which is often outside our control. That said, the second issue you mentioned (TOTP session timeout) does seem unusual. Android returning an
unknown
error code is not expected. I will go ahead and create a PR to address that.IshchikGL commentedon Apr 25, 2025
@SelaseKay thanks for the effort
So, in case of iOS session timeout, will we be getting that message pointing to nothing? We can't fully rely on the code we get
Let me know if I can assist
MichaelVerdon commentedon Apr 30, 2025
Hey there, after trying to reproduce, we been getting different errors. [enroll-failed] every time for any issue. Can you please provide some steps you took to get the exact error codes?
IshchikGL commentedon May 1, 2025
@MichaelVerdon we have users already enrolled for TOTP 2FA. Please, check the cases described above.
User has to use any of available sign-in methods from FirebaseAuth and then he's prompted to enter the TOTP code.
After that there are few cases you can try to reproduce:
Please, let me know if you need any information
MichaelVerdon commentedon May 2, 2025
Hi there, understood. We tried exactly that and got different errors retrieved but will give it a go again.