Firebase Auth仅返回INVALID_LOGIN_CREDENTIALS错误,禁用邮箱枚举保护失败
登录时Firebase Auth错误码统一返回INVALID_LOGIN_CREDENTIALS的问题
在Flutter/Dart代码中调用FirebaseAuth.instance.signInWithEmailAndPassword()实现邮箱密码登录,为区分用户输入错误密码、不存在邮箱等场景,我原本计划捕获user-not-found、invalid-email、user-disabled、wrong-password这些具体错误码,但实际测试时所有错误场景都仅返回INVALID_LOGIN_CREDENTIALS这一个统一错误码。
登录实现代码
Future<AuthResult> signIn(String email, String password) async { try { await FirebaseAuth.instance.signInWithEmailAndPassword( email: email, password: password, ); return AuthResult.success; } on FirebaseAuthException catch (e) { print(e.code); switch (e.code) { case 'user-not-found': return AuthResult.userNotFound; case 'invalid-email': return AuthResult.invalidEmail; case 'user-disabled': return AuthResult.userDisabled; case 'wrong-password': return AuthResult.wrongPassword; default: return AuthResult.failure; } } catch (_) { return AuthResult.aborted; } }
尝试禁用邮箱枚举保护时的报错
查Stack Overflow和GitHub后得知,该问题与Firebase的邮箱枚举保护机制有关。我按照Google Cloud文档步骤尝试禁用该功能,但执行命令时在Google Cloud控制台出现以下错误:
curl: (3) URL using bad/illegal format or missing URL curl: (6) Could not resolve host: Bearer curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL curl: (6) Could not resolve host: application curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL { "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED", "details": [ { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "CREDENTIALS_MISSING", "domain": "googleapis.com", "metadata": { "service": "identitytoolkit.googleapis.com", "method": "google.cloud.identitytoolkit.admin.v2.ProjectConfigService.UpdateConfig" } } ] } }
内容的提问来源于stack exchange,提问作者Mohammed Jamal
相关产品推荐
相关产品推荐

