1

I'm trying to use firebase google authentication for my Android App. Firstly I initialize Google Client as a documentation :

 gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build()
 mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

Google Sign-In button click listener:

googleSignInBtn.setOnClickListener({
        val signInIntent = mGoogleSignInClient.signInIntent
        startActivityForResult(signInIntent, RC_SIGN_IN) 
       })

My activity result :

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
                super.onActivityResult(requestCode, resultCode, data)
                if (requestCode == RC_SIGN_IN) {
                    val task: Task<GoogleSignInAccount> = GoogleSignIn.getSignedInAccountFromIntent(data)
                    try {
                        val account = task.getResult(ApiException::class.java)
                        firebaseAuthWithGoogle(account)
                    } catch (e: ApiException) {
                        Log.w(TAG, "Google sign in failed status code:"+e.statusCode);
                    }
                } 
            }

I added both release and debug sha-1 fingerprint to firebase console. There is no problem in debugging mode, it works. But when I'm trying in release mode , I'm getting DEVELOPER ERROR. How can I fix this problem ? Thank you.

yusufonderd
  • 3,237
  • 4
  • 21
  • 34
  • 1
    I too am struggling with the same issue. Did you find any solution? – Hanu Nov 19 '17 at 19:07
  • Find sha-1 fingerprint from Google play developer console . Then add this sha-1 to Firebase console. – yusufonderd Nov 20 '17 at 06:38
  • Would there be a SHA1 key that google play developer console generates? I was thinking that only development system generates a sha1. Am I getting this right? – Hanu Nov 20 '17 at 08:55
  • Actually I don’t know. But I show you how to get sha-1 from Google play for Firebase in today. I’m mobile now . – yusufonderd Nov 20 '17 at 09:37
  • Finally I found solution. Check this answer : https://stackoverflow.com/a/45273726/3170065 – yusufonderd Nov 21 '17 at 08:25

1 Answers1

0

I too am stuck at the same point in my project release and couldnt understand what was causing the trouble even after adding the SHA1 keys of debug and release. It is more than this for me. It was working fine till I started signing my build and later I realized that my debug build started failing with the same error. What it means is, I had a working solution which I want to sign with release keys and that didnt work and I was playing with proguard rules to make it work and ended up adding SHA1 release key. In this whole excitement to make it work, at some point, I lost my original functionality, i.e. my debug build also started failing with the same issue even if I didnt remove my debug key. This made to start working on this from scratch and thats when I realized that this whole process could have been lot simpler.

Workaround Answer

Following the google docs link here, I created a new activity and came up with below code and it worked with debug and release keys like a charm.

List<AuthUI.IdpConfig> providers = Arrays.asList(
            new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build(),
            new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build()
        );
            // Create and launch sign-in intent
           startActivityForResult(
               AuthUI.getInstance()
               .createSignInIntentBuilder()
               .setAvailableProviders(providers)
               .setTheme(R.style.LoginTheme)
               .build(),
               RC_SIGN_IN);

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);

            if (requestCode == RC_SIGN_IN) {
                IdpResponse response = IdpResponse.fromResultIntent(data);
                if (resultCode == RESULT_OK) {
                    // Successfully signed in
                    showProgressDialog();
                    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                    if (user != null) {
                        user.getIdToken(true).addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
                        @Override
                       public void onComplete(@NonNull Task<GetTokenResult> task) {
                                if (task.isSuccessful()) {
                                    String idToken = task.getResult().getToken();
                                    getCustomJWToken(idToken);
                                }
                            }
                        });
                    } else {
                        Toast.makeText(FirebaseLogin.this, 
                        R.string.firebase_auth_error, Toast.LENGTH_SHORT).show();
                    }
                    hideProgressDialog();
                } else {
                    Toast.makeText(FirebaseLogin.this, R.string.invalid_credentials, 
                     Toast.LENGTH_SHORT).show();
                }
            }
        }

Hope this helps somebody out there.

Hanu
  • 1,087
  • 11
  • 21