firebase / FirebaseUI-Android

Optimized UI components for Firebase
https://firebaseopensource.com/projects/firebase/firebaseui-android/
Apache License 2.0
4.63k stars 1.83k forks source link

Error: Failed to build credentials for Facebook, Twitter and Google #1628

Closed HelaGone closed 4 years ago

HelaGone commented 5 years ago

Hello everyone! I don't understand why Firebase UI isn't capable to build and store the user's credentials. Here's the problem:

Step 2: Describe your environment

Step 3: Describe the problem:

The problem is that Firebase UI is not building the appropriate credentials for the signed in user and therefore each time the user wants to login in the application it is prompted to follow along the whole process of signing in instead of just logging the user with its credentials

Steps to reproduce:

  1. Follow the instructions in https://firebase.google.com/docs/auth/android/firebaseui?authuser=1
  2. Enable Facebook, Google, Twitter and Email/Password providers
  3. Try to sign in with Facebook or Google or Twitter an search in the android studio's Logcat for the error: E/AuthUI: A sign-in error occurred. com.firebase.ui.auth.FirebaseUiException: Failed to build credential.
    1. Logout and login again and see how the sign up flow starts again because there are no credentials saved to identify the returning user.

I've already checked that my application is not listed under "Never Save" option in the Smart Lock for Passwords in the device.

Observed Results:

2019-04-30 18:19:16.954 19268-19268/com.iphoideas.android.myorganization E/AuthUI: A sign-in error occurred.
    com.firebase.ui.auth.FirebaseUiException: Failed to build credential.
        at com.firebase.ui.auth.viewmodel.smartlock.SmartLockHandler.saveCredentials(SmartLockHandler.java:76)
        at com.firebase.ui.auth.ui.credentials.CredentialSaveActivity.onCreate(CredentialSaveActivity.java:67)
        at android.app.Activity.performCreate(Activity.java:7032)
        at android.app.Activity.performCreate(Activity.java:7023)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1236)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2943)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1630)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6626)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

Expected Results:

The expected result is the build and save of the user's credentials in the Smart Lock for Passwords. Which is not happening.

Relevant Code:

This is called when te user clicks on the login button

private void signInFlowIntent(){
        startActivityForResult(
                AuthUI.getInstance()
                        .createSignInIntentBuilder()
                        .setIsSmartLockEnabled(true)
                        .setAvailableProviders(providers)
                        .build(), RC_SIGN_IN);
    }

And this is called when the result is received

@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){
                Toast.makeText(getApplicationContext(), "Logged in user", Toast.LENGTH_SHORT).show();
                //Successfully signed in
                FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                Log.d(TAG, "user: " + user.getDisplayName());
                updateLogInMenuItems(true, user );

            }else{
                if(response == null){
                    Log.d(TAG, "Response Null: " + response.getError().getErrorCode());
                    return;
                }

                if(response.getError().getErrorCode() == ErrorCodes.NO_NETWORK){
                    Log.d(TAG, "ERROR NO INTERNET CONNECTION" + response.getError().getErrorCode());
                }
                Log.d(TAG, "ERROR SIGNING IN USER" + response.getError());
            }
        }
    }
samtstern commented 5 years ago

@HelaGone does smartlock work when you're using Email/Password accounts? I believe we don't save any credential for social accounts, since there is really nothing to save. The social providers implement SSO themselves.

HelaGone commented 5 years ago

@samtstern Yes Smart Lock works fine with Email/Password. If you don't save any credentials for social accounts how the application know if the user is already registered? And why is that error being logged in the logcat? Also, Why is this stated in the docs?

By default, FirebaseUI uses Smart Lock for Passwords to store the user's credentials and automatically sign users into your app on subsequent attempts.

https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md?authuser=1#smart-lock

samtstern commented 5 years ago

@HelaGone you're right that we should definitely keep that error from being logged if it's intended behavior!

I will have to go find the old discussion, but I believe we decided that for all account types besides Phone or Email, SmartLock was not a great user experience. The prompt dialog has no way of indicating which social provider it has saved, and in the end we can't guarantee that sign in will succeed we can only launch the social flow.

samtstern commented 5 years ago

@SUPERCILEX do you remember any of these discussions?

HelaGone commented 5 years ago

Are you telling me that I should not care about that error and disable Smart Lock for Passwords as described in the docs with setIsSmartLockEnabled(false)?

samtstern commented 5 years ago

@HelaGone just to be clear: when you try to sign in with Google/Facebook does it succeed with errors in the logs or does it fail completely?

HelaGone commented 5 years ago

@samtstern It succeed with the mentioned error, and the user is signed in. I can get the current user data (Name, Photo, Uid, Etc)

samtstern commented 5 years ago

@HelaGone ok in that case I would say you should keep SmartLock enabled and ignore the logs for now, with the understanding that SmartLock is only working for Email/Phone accounts right now. We will try to address this in a future bugfix release. Thank you for all the information!

HelaGone commented 5 years ago

Here is more Log Juice in case you need it:

2019-05-02 11:46:04.604 1989-2091/com.iphoideas.android.myorganization D/FA: Connected to remote service
2019-05-02 11:46:04.616 1989-1989/com.iphoideas.android.myorganization W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzam@d61911b
2019-05-02 11:46:04.618 1989-1989/com.iphoideas.android.myorganization E/Twitter: Authorize not in progress
2019-05-02 11:46:04.643 1989-1989/com.iphoideas.android.myorganization W/PropertyValuesHolder: Method set() with type float not found on target class class me.zhanghai.android.materialprogressbar.IndeterminateHorizontalProgressDrawable$RectTransformX
2019-05-02 11:46:05.371 1989-2003/com.iphoideas.android.myorganization D/FirebaseAuth: Notifying id token listeners about user ( L5NyrhtJiChgc4WL9XJ2M2M6njN2 ).
2019-05-02 11:46:05.371 1989-2003/com.iphoideas.android.myorganization D/FirebaseAuth: Notifying auth state listeners about user ( L5NyrhtJiChgc4WL9XJ2M2M6njN2 ).
2019-05-02 11:46:05.379 1989-1989/com.iphoideas.android.myorganization D/FirebaseApp: Notifying auth state listeners.
2019-05-02 11:46:05.380 1989-1989/com.iphoideas.android.myorganization D/FirebaseApp: Notified 0 auth state listeners.
2019-05-02 11:46:05.543 1989-1989/com.iphoideas.android.myorganization D/CredentialSaveActivity: Launching save operation.
2019-05-02 11:46:05.549 1989-1989/com.iphoideas.android.myorganization E/AuthUI: A sign-in error occurred.
    com.firebase.ui.auth.FirebaseUiException: Failed to build credential.
        at com.firebase.ui.auth.viewmodel.smartlock.SmartLockHandler.saveCredentials(SmartLockHandler.java:76)
        at com.firebase.ui.auth.ui.credentials.CredentialSaveActivity.onCreate(CredentialSaveActivity.java:67)
        at android.app.Activity.performCreate(Activity.java:7032)
        at android.app.Activity.performCreate(Activity.java:7023)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1236)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2814)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2943)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1630)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6626)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
2019-05-02 11:46:05.620 1989-1989/com.iphoideas.android.myorganization E/Twitter: Authorize not in progress
2019-05-02 11:46:05.690 1989-1989/com.iphoideas.android.myorganization D/MainActivity: User Logged >>>> Stephen Jane
SUPERCILEX commented 5 years ago

@samtstern the discussion was here: https://github.com/firebase/FirebaseUI-Android/issues/1154. From what I remember, we try saving all credentials so that they're available to use for us and the app developer. When the user tries signing in again, we only show easy to use IDPs (only Google right now). So yeah, the above looks like a bug.

samtstern commented 4 years ago

Ok digging into this I believe this happens when email is null, which can happen due to #1621 but a fix for that has already been implemented.

I was able to build credentials for Google and Facebook accounts in my testing, I will add some extra logging around this case but for now I believe that's all I can do (in addition to other fixes).

samtstern commented 4 years ago

The fix for this issue has been released in version 6.2.1