Search code examples
androidauthenticationfirebase-authentication

Authentication with Google on Firebase returns CANCELED


I've been looking for the cause of this problem and I've already tested several ways that I saw here on Stack Overflow, but nothing seems to solve the problem.

Basically, I'm trying to authenticate through Google, and when I get to the Google account selection page and it returns to my activity, I always see a result of RESULT_CANCELED (0) instead of RESULT_OK (-1), regardless of the account selected. .

I checked that the credentials are configured correctly in the Google Console and that the SHA-1 caves (debug and release) were added correctly. I even deleted my firebase project and created a new one following the step by step instructions but nothing helped.

My call for authentication:

 GoogleSignInOptions googleSignInOptions = new                GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.client_id_google))
            .requestEmail()
            .build();

    googleSignInClient = GoogleSignIn.getClient(LoginActivity.this, googleSignInOptions);
    firebaseAuth = FirebaseAuth.getInstance(); 

And the ActivityResultLauncher that expects the result:

mStartForResult = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
            result -> {
                if (result.getResultCode() == Activity.RESULT_OK) {
                    getInformationSignedAccountGoogle(result.getData());
                }
            });

Solution

  • some API keys were generated incorrectly. I deleted it and generated it again and it started working correctly.