Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Android: Google Sign In Failure

First of all, I have to say I'm very very new to Android development so forgive me if I overlook something obvious.

For a university project, I have to create an app that first authenticates users via their Google Account using Firebase. I first followed the instructions I found here.

For a start, I copy pasted this code from Firebase Tutorial. Everything seems to be working, except for one thing :

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "------------------ onActivityResult ------------------");
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            Log.d(TAG, "------------------ googleSignInSuccess ------------------");
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = result.getSignInAccount();
            firebaseAuthWithGoogle(account);
            // Start menu activity once the user has been logged in
            Intent intent = new Intent(this, MenuActivity.class);
            startActivity(intent);
        } else {
            Log.d(TAG, "------------------ googleSignInFailure ------------------");
            // Google Sign In failed, update UI appropriately
            // [START_EXCLUDE]
            //Log.d(TAG, result.getStatus().getStatusMessage());
            updateUI(null);
            // [END_EXCLUDE]
        }
    }
}

Here, result.isSuccess() == false. So I think the Google authentication fails for some reason I cannot understand. I am sure I entered the right password, I also enabled Google Account authentication in my app's Firebase Console.

Thank you very much in advance if you can help me.

EDIT : To be more precise, the first time I run the program on my emulator (or after each time I wipe data from it), I have to enter my Google credentials in the dedicated Google login activity that pops up. This works fine and the same activity seems to successfully authenticate me. However after that, result.isSuccess() is still false and I don't understand why.

like image 796
Scrashdown Avatar asked Oct 11 '16 21:10

Scrashdown


People also ask

How do I sign into Google Firebase on Android?

In the Firebase console, open the Auth section. On the Sign in method tab, enable the Google sign-in method and click Save.

Is Firebase down today?

Current Firebase status is up.

How do I get Firebase Authentication error message?

Each user must have a unique email. The provided Firebase ID token is expired. The Firebase ID token has been revoked. The credential used to initialize the Admin SDK has insufficient permission to access the requested Authentication resource.


2 Answers

I finally found the problem, I made a mistake while authenticating my app in the Firebase Console here (section "before you begin"), 4th step. I entered the debug one instead and it works now.

Thanks nonetheless!

like image 155
Scrashdown Avatar answered Sep 28 '22 04:09

Scrashdown


You can check status of the result with result.getStatus().getStatusMessage(). Log this message or debug your result Status and it should indicate issue. Status has also getResolution() method that provides pending intent that should resolve your failure (firstly check if resolution is available with calling hasResolution(), which returns true if it can handle it for you).

like image 32
pawegio Avatar answered Sep 28 '22 04:09

pawegio