14

I've been going through the Firebase docs to set up a user authentication system in my android app. For some reason however, it doesn't look like any of the callbacks are running on my FirebaseAuth object!

For example with setting up the Facebook authentication as instructed here

private void handleFacebookAccessToken(AccessToken token) {
    Log.d("AUTH", "handleFacebookAccessToken:" + token.getToken());
    // ...
    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    Log.d("AUTH", "Credential: "+credential);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d("AUTH", "signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w("AUTH", "signInWithCredential", task.getException());
                        Toast.makeText(LoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // ...
                }
            });
}

Everything fine on the part of Facebook but when it comes to signing in with the retrieved fb credentials, the signInWithCredential function doesn't run any callbacks and nothing seems to happen in my user database.

Furthermore I've tried the much more simpler

mAuth.createUserWithEmailAndPassword(etUserID.getText().toString(), etPassword.getText().toString());

and nothing happens as well. I've enabled both providers in my Firebase console and downloaded the latest google-services.json file for the project. Am I missing something?

EDIT: Just tried running the quick-start authentication demo and it doesn't work as well. I do see on my emulator that this app won't run unless I update google services. Is this the cause of this error? I tried updating google services on various emulators and that just returns an error.

tetutato
  • 638
  • 5
  • 16
  • I believe issue has something to do with the callback not finishing since none of the callbacks fire... similar to this issue: http://stackoverflow.com/questions/29975024/firebase-java-android-createuser-failing – tetutato May 23 '16 at 00:54
  • I'm seeing the same. Tried custom and anonymous auth, neither of them works. Callbacks just aren't called. – biasedbit May 31 '16 at 01:09

6 Answers6

6

Got it working only on a real android device, but had no lucky with the emulator.

For the device, you'll need to add the following dependency in your app gradle file:

compile 'com.google.android.gms:play-services-auth:9.0.2'

I haven't tested, but it seems that if you update the emulator image with a newer google play services, it also should work.

Hope it helps.

feroult
  • 493
  • 5
  • 12
4

Solved it thanks to @feroult post and other resources. In my case OnCompleteListener was never called after I updated the build.gradle with the new version of Play Services Library and Firebase libraries. The solution is to update the Play Services App installed on the Emulator.

In my case it started working with 11.0.4 version of Play services library and 11.3.02 version of Play Services app installed on Emulator.

enter image description here enter image description here

vovahost
  • 34,185
  • 17
  • 113
  • 116
3

It seems like the issue is caused by certain emulators not supporting the latest versions of Google Play Services! (You will see an error in logcat) Galaxy Nexus 5x API 23 w/ Google APIs seem to work with logins.

tetutato
  • 638
  • 5
  • 16
  • were you able to figure this one out? I am running Nexus 5 and it is task.isSuccessful() is always false. No matter what I do, not sure what to do at this point? – jason adams Jul 09 '16 at 05:52
  • You must be doing something wrong with getting the credentials. I was having problem even getting the onComplete to fire, but I'm guessing that's working for you and you're checking the task.isSuccessful() value there. – tetutato Jul 17 '16 at 01:17
0

I had the same issue and eventually in my case i forgot enable it in firebase console

enter image description here

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
0

On a physical device, I did need to update Google Play Services in order to get the callback to work

Gene Bo
  • 11,284
  • 8
  • 90
  • 137
0

I had the same problem here, and the solution was very simple: stop using the emulator and start using a physical device to test the application. I don't know why, but it seems like the emulator has some problems dealing with firebase :/