Firebase 验证码检查失败并阻止用户进行身份验证
Posted
技术标签:
【中文标题】Firebase 验证码检查失败并阻止用户进行身份验证【英文标题】:Firebase captcha check fails and prevents user from authenticating 【发布时间】:2021-02-23 10:27:58 【问题描述】:我不知道为什么会弹出这个错误。当我在其他设备上运行该应用程序时,该应用程序运行良好,但当我在其他设备上遇到问题时。当我通过 wifi 访问 firebase 时,我也遇到了问题。我已经联系了 Firebase 支持,他们说他们在印度遇到了服务器和 isp 的问题
otpVerification.kt
const val USER_REF:String="user"
class OtpVerification : AppCompatActivity()
lateinit var auth: FirebaseAuth
private var mAuthVerificationId: String? = null
private var mOtpText: EditText? = null
private var mVerifyBtn: Button? = null
private var mOtpProgress: ProgressBar? = null
private var mOtpFeedback: TextView? = null
lateinit var email:String
lateinit var password: String
private lateinit var database: DatabaseReference
lateinit var uname:String
lateinit var mCurrentUser: FirebaseUser
override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_otp_verification)
mAuthVerificationId = intent.getStringExtra("AuthCredentials")
Log.d("AuthCredentials", mAuthVerificationId.toString())
email= intent.getStringExtra("email").toString()
password= intent.getStringExtra("password").toString()
uname= intent.getStringExtra("name").toString()
mOtpFeedback = findViewById(R.id.otp_form_feedback)
mOtpProgress = findViewById(R.id.otp_progress_bar)
mOtpText = findViewById(R.id.otp_text_view)
auth=Firebase.auth
database = FirebaseDatabase.getInstance().reference
mVerifyBtn = findViewById(R.id.verify_btn)
mVerifyBtn?.setOnClickListener(View.OnClickListener
val otp = mOtpText?.text.toString()
if (otp.isEmpty())
mOtpFeedback?.visibility = View.VISIBLE
mOtpFeedback?.text = "Please fill in the form and try again."
else
mOtpProgress?.visibility = View.VISIBLE
mVerifyBtn?.isEnabled = false
val credential = PhoneAuthProvider.getCredential(mAuthVerificationId!!, otp)
signInWithPhoneAuthCredential(credential)
)
private fun signInWithPhoneAuthCredential(credential: PhoneAuthCredential)
auth?.signInWithCredential(credential)
?.addOnCompleteListener(this,
OnCompleteListener<AuthResult?> task ->
if (task.isSuccessful)
createAccount(email,password)
mCurrentUser= auth.currentUser!!
Prefs.put(this, mCurrentUser)
Log.d("user",mCurrentUser.toString())
sendUserToHome()
Log.d("TAG", "Task is succesful")
// ...
else
if (task.exception is FirebaseAuthInvalidCredentialsException)
// The verification code entered was invalid
mOtpFeedback?.visibility = View.VISIBLE
mOtpFeedback?.text = "There was an error verifying OTP"
mOtpProgress?.visibility = View.INVISIBLE
mVerifyBtn?.isEnabled = true
)
fun sendUserToHome()
val intent = Intent(this, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)
finish()
private fun createAccount(email: String, password: String)
Log.d("TAG", "createAccount:$email.toString()")
//Log.d("TAG", "validate form is $validateForm().toString()")
// [START create_user_with_email]
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this) task ->
if (task.isSuccessful)
// Sign in success, update UI with the signed-in user's information
Log.d("TAG", "createUserWithEmail:success")
val user = auth.currentUser
Toast.makeText(baseContext, "Authentication Success $user", Toast.LENGTH_SHORT)
.show()
sendEmailVerification()
val intent = Intent(this, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
startActivity(intent)
Log.d("Delete", "deleting activity signup")
finish()
else
// If sign in fails, display a message to the user.
Log.w("TAG", "createUserWithEmail:failure", task.exception)
Toast.makeText(
baseContext, "Authentication failed.",
Toast.LENGTH_SHORT
).show()
// updateUI(null)
// [START_EXCLUDE]
// [END_EXCLUDE]
// [END create_user_with_email]
createUSer()
private fun sendEmailVerification()
// Send verification email
// [START send_email_verification]
val user = auth.currentUser!!
user.sendEmailVerification()
.addOnCompleteListener(this) task ->
if (task.isSuccessful)
Toast.makeText(baseContext,
"Verification email sent to $user.email ",
Toast.LENGTH_SHORT).show()
Log.d("TAG", "sendEmailVerification")
else
Log.d("TAG", "sendEmailVerification", task.exception)
Toast.makeText(baseContext,
"Failed to send verification email.",
Toast.LENGTH_SHORT).show()
// [END_EXCLUDE]
// [END send_email_verification]
fun createUSer()
database.child(USER_REF).child(uname).child("email").setValue(email)
Log.d("CREATED","create user"+uname)
日志猫
2020-11-11 17:57:45.290 28364-28364/com.bva_valai_pada E/zza: Problem
retrieving SafetyNet Token: 7:
2020-11-11 17:57:45.358 28364-28364/com.bva_valai_pada W/ActivityThread:
handleWindowVisibility: no activity for token android.os.BinderProxy@5308a64
2020-11-11 17:57:45.873 28364-30352/com.bva_valai_pada E/FirebaseAuth:
[GetAuthDomainTask] Error getting project config. Failed with
"error":
"code": 400,
"message": "INVALID_CERT_HASH",
"errors": [
"message": "INVALID_CERT_HASH",
"domain": "global",
"reason": "invalid"
]
400
2020-11-11 17:57:45.919 28364-28364/com.bva_valai_pada E/zza: Failed to get
reCAPTCHA token - calling backend without app verification
2020-11-11 17:57:45.962 28364-28364/com.bva_valai_pada I/AssistStructure:
Flattened final assist data: 4392 bytes, containing 1 windows, 13 views
2020-11-11 17:57:45.966 28364-28410/com.bva_valai_pada W/System: Ignoring
header X-Firebase-Locale because its value was null.
2020-11-11 17:57:46.611 28364-28410/com.bva_valai_pada E/FirebaseAuth:
[SmsRetrieverHelper] SMS verification code request failed: unknown status
code: 17093 null
2020-11-11 17:57:46.621 28364-28364/com.bva_valai_pada D/Exception:
com.google.firebase.auth.FirebaseAuthException: This request is missing a
valid app identifier, meaning that neither SafetyNet checks nor reCAPTCHA
checks succeeded. Please try again, or check the logcat for more details.
【问题讨论】:
嘿!你找到解决办法了吗? 是的,我没有在 firebase 项目中添加我的 SHA-1 密钥,添加后,我的问题得到了解决 【参考方案1】:您需要按照以下简单方法将指纹添加到您的 firebase 项目
-
转到您的 android 工作室并从右上角打开 Gradle 选项卡。
您的应用名称 > 运行配置 > ..[signingReport]> 双击
从底部查看终端窗口并复制 SHA-1 和 SHA-256 行
转到 firebase.google.com > 选择您的项目 > 项目设置 > 常规
点击添加指纹并粘贴您复制的密钥,不包括 SHA-1 或 SHA-256 名称
点击添加并重新启动应用程序。
【讨论】:
【参考方案2】:第 1 步:选择一个项目。
第 2 步:启用 Android 设备验证
使用下面的链接启用 Android 设备验证。
https://console.cloud.google.com/apis/library/androidcheck.googleapis.com
【讨论】:
【参考方案3】:您的问题与 SHA1 和 SHA256 密钥有关。您必须添加它们来验证您的证书。
列表项
转到
您的项目身份验证项目设置的 Firebase 控制台(来自 项目概述附近的设置按钮)添加指纹添加SHA-1和 密钥库的 SHA-256 值。您可以从 gradle 获取密钥库 像这样。
./gradlew 签名报告
阅读本文了解更多信息:https://firebase.google.com/docs/auth/android/phone-auth#enable-app-verification
【讨论】:
感谢您的努力,但我已经得到答案并标记为正确【参考方案4】:啊,您似乎需要在 Firebase 控制台中的应用注册中添加 SHA-1 证书哈希。我认为您可以找到执行此操作的说明here
【讨论】:
以上是关于Firebase 验证码检查失败并阻止用户进行身份验证的主要内容,如果未能解决你的问题,请参考以下文章
Firebase 电话身份验证在已投入生产的应用程序上失败,状态码为 17028
Nativescript Vue + Firebase 身份验证:检查用户是不是在每个组件中进行身份验证的最佳方法?