1

I ran into some strange issue with Google-Authentication through Firebase.

When I install it from google play store, google-authentication fails to work, but in the other hand when I install it locally from Android studio (same version), it does work.

the following is the authentication function -

private fun signInWithGoogle() {
    // Configure Google Sign In
    val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestIdToken(getString(R.string.default_web_client_id))
        .requestEmail()
        .build()
    googleSignInClient = GoogleSignIn.getClient(requireContext(), gso)
    val signInIntent = googleSignInClient.signInIntent
    getResult.launch(signInIntent)
}

private val getResult =
    registerForActivityResult(
        ActivityResultContracts.StartActivityForResult()) {
        if (it.resultCode == Activity.RESULT_OK) {

            val task = GoogleSignIn.getSignedInAccountFromIntent(it.data)
            if (task.isSuccessful) {
                try {
                    // Google Sign In was successful, authenticate with Firebase
                    val account = task.getResult(ApiException::class.java)!!

                    firebaseAuthWithGoogle(account.idToken!!)
                } catch (e: ApiException) {
                    // Google Sign In failed, update UI appropriately

                }

            } else {
                println(task.exception?.message)
            }


        }
    }

private fun firebaseAuthWithGoogle(idToken: String) {
    val credential = GoogleAuthProvider.getCredential(idToken, null)
    mAuth.signInWithCredential(credential)
        .addOnCompleteListener { task ->
            if (task.isSuccessful) {
                // Sign in success, update UI with the signed-in user's information
                println("signInWithCredential:success")

                startActivity(Intent(activity, MainActivityApplication::class.java))
                activity?.finish()


            } else {
                // If sign in fails, display a message to the user.
                println("signInWithCredential:failure ${task.exception}")

            }
        }
        .addOnFailureListener {
            println(it.message)
            binding.pbGoogleBtn.visibility= View.GONE
        }
}
מגן לוי
  • 49
  • 1
  • 7
  • 1
    Most likely it's because of [this](https://stackoverflow.com/questions/51360250/firebase-ui-authentication-with-google-fails-with-message-code10-message10/51360406). – Alex Mamo Mar 11 '22 at 10:52
  • Thanks!! I probably missed the last stop of setting "Google Play App signing key" – מגן לוי Mar 12 '22 at 12:45

0 Answers0