Moh*_*mal 4 firebase google-cloud-platform firebase-authentication flutter
当我在 Flutter/Dart 代码中使用 FirebaseAuth.instance.signInWithEmailAndPassword() 时,测试用户输入错误密码或错误电子邮件等的场景。要获取错误代码,例如:“用户未找到” 、“无效电子邮件”、“用户已禁用”或“密码错误”。问题是我得到的唯一错误代码是“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;
}
}
Run Code Online (Sandbox Code Playgroud)
我还查看了 StackOverFlow 和 Github,看看其他人是否也遇到这个问题。看起来它与电子邮件枚举保护有关。我查看了 Google Cloud 文档以了解如何禁用此功能,但这并没有解决我的问题,按照说明进行操作。
有关如何禁用它的链接:https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection#disable
这是我按照说明操作时在 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"
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
对于 2023 年 9 月 15 日以来创建的 Firebase 项目,默认启用防止电子邮件枚举的设置。此设置使恶意用户更难通过更改某些 API 的响应并完全禁用其他 API 来找出您的项目中的用户。
您所看到的是此设置的结果,该结果记录在电子邮件枚举保护的此页面上。
该页面还展示了如何禁用电子邮件枚举保护,以便 API 恢复到之前的行为。请注意,这样做将使您的项目/用户容易受到电子邮件枚举攻击的风险。
| 归档时间: |
|
| 查看次数: |
1017 次 |
| 最近记录: |