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

Sign-in intent gets suck and never launched #2066

Open zjamshidi opened 2 years ago

zjamshidi commented 2 years ago

Describe your environment

Step 3: Describe the problem:

Some users reported the authentication picker activity is not loaded. When they tap on the button which launches the sign-in intent they get stuck.

Steps to reproduce:

I couldn't replicate it on my device.

Observed Results:

I guessed it might be related to Google Smart lock, so I asked the users to remove the credentials or app or even disable it but they didn't help.

Relevant Code:

    private void onLoginButton(View view) {
        ...
        startActivityForResult(buildSignInIntent(), RC_SIGN_IN);
        ...
    }

    @NonNull
    private Intent buildSignInIntent() {
        List<AuthUI.IdpConfig> selectedProviders = new ArrayList<>();
        selectedProviders.add(new AuthUI.IdpConfig.EmailBuilder().build());
        selectedProviders.add(new AuthUI.IdpConfig.FacebookBuilder().build());
        selectedProviders.add(new AuthUI.IdpConfig.GoogleBuilder().build());

        AuthUI.SignInIntentBuilder builder = AuthUI.getInstance().createSignInIntentBuilder()
                .setLogo(AuthUI.NO_LOGO)
                .setTheme(R.style.AppTheme)
                .setIsSmartLockEnabled(!BuildConfig.DEBUG /* credentials */, true /* hints */)
                .setAvailableProviders(selectedProviders);

        AuthMethodPickerLayout customLayout = new AuthMethodPickerLayout
                .Builder(R.layout.fragment_register)
                .setGoogleButtonId(R.id.custom_google_signin_button)
                .setEmailButtonId(R.id.custom_email_signin_button)
                .setFacebookButtonId(R.id.custom_facebook_signin_button)
                .setTosAndPrivacyPolicyId(R.id.custom_tos)
                .build();

        builder.setAuthMethodPickerLayout(customLayout);

        builder.setTosAndPrivacyPolicyUrls(Constants.TermsOfUseURL, Constants.PrivacyPolicyURL);

        return builder.build();
    }
thatfiredev commented 2 years ago

@zjamshidi I see you're testing in version 7.1.1 of FirebaseUI. Can you please test it in the latest version (8.0.2)?

zjamshidi commented 1 year ago

We have released a new version with 8.0.1 and I'm waiting for feedbacks.

leocorder commented 1 year ago

Same problem here using 8.0.1.

BoyanJIliev commented 1 year ago

I have the same problem here using 8.0.2. Phone: Samsung Galaxy A3 a320 firebase-auth: 21.1.0

jftabord commented 1 year ago

We had the same problem using 8.0.0, and as a workaround in one of the phones we use for testing, we cleaned the "google play services" cache and it resolves the issue. The list of devices where we have the issue reported:

Xiaomi Redmi 9A/x64/Android 11 API 30 Vivo/x64/Android 12 API 31

com.firebaseui:firebase-ui-auth:8.0.0 com.google.firebase:firebase-bom:30.0.1

nverinaud commented 1 year ago

Same problem here.

OnePlus Nord 2 / Android 12

com.firebaseui:firebase-ui-auth:8.0.1 com.firebaseui:firebase-ui-storage:8.0.1 com.google.firebase:firebase-bom:30.4.0

Clearing cache and app storage solved the issue.

danielrrv commented 1 year ago

Digging deeper into the issue where the intent never shows the providers, we(@jftabord) found that the error has something to do with missing credentials in the Smart Lock for passwords and Connected Account at phone vaults.

  1. We debugged all the transactions from launching the intent on the onCreate@KickoffActivity until the SignInKickStarter.javaL97
  2. The execution got stuck at https://github.com/firebase/FirebaseUI-Android/blob/5b6c9f01f5a674d754d8e9b1242197fe040086e7/auth/src/main/java/com/firebase/ui/auth/data/remote/SignInKickstarter.java#L97-L121
  3. In the phone stack we started to see some exceptions as follows.
    
    10-27 17:47:28.209  8195 30292 E AuthPII : [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/cclog
    10-27 17:47:28.209  8195 30292 E AuthPII : aaky: Long live credential not available.
    ...
    10-27 17:47:28.244  8195 30292 E AuthPII : Message is Long live credential not available.
    10-27 17:47:28.244  8195 30292 E AuthPII : aaky: Long live credential not available.
    10-27 17:47:28.244  8195 30292 E AuthPII :  at kzz.a(:com.google.android.gms@224113024@22.41.13 (100300-480714934):8)
    ...
    10-27 17:47:28.244  8195 30292 W Auth    : [GetToken] GetToken failed with status code: BadAuthentication
    10-27 17:47:28.258  8195 30292 W Auth    : [GoogleAuthUtil] isUserRecoverableError status: BAD_AUTHENTICATION
    10-27 17:47:28.259  8195 30292 W GoogleAuthUtil: Error when getting token

4. We believed that it has something to do with credential, therefore, in another physical phone, we changed the password on google's end and we removed the google play services mimicking the situation where the Oauth token is not available. Then we were able to reproduce the bug.

5. There's a special exception `com.google.android.gms.auth.UserRecoverableAuthException` in the same sequences of errors that we guess isn't handled by FirebaseUI. Might be a very rare situation to handle.  

operation=List, opStatusCode=11005 [CONTEXT service_id=80 ] 10-27 17:47:46.706 15044 15507 W AsyncOperation: OperationException[Status{statusCode=Error retrieving oauth token, resolution=PendingIntent{4d2f308: android.os.BinderProxy@40e1aa1}}] 10-27 17:47:46.706 15044 15507 W AsyncOperation: at zdl.c(:com.google.android.gms@224113024@22.41.13 (100300-480714934):14) 10-27 17:47:46.706 15044 15507 W AsyncOperation: at zdl.d(:com.google.android.gms@224113024@22.41.13 (100300-480714934):16) 10-27 17:47:46.706 15044 15507 W AsyncOperation: at zdl.f(:com.google.android.gms@224113024@22.41.13 (100300-480714934):4) 10-27 17:47:46.706 15044 15507 W AsyncOperation: at asna.er(:com.google.android.gms@224113024@22.41.13 (100300-480714934):1) 10-27 17:47:46.706 15044 15507 W AsyncOperation: at asng.run(:com.google.android.gms@224113024@22.41.13 (100300-480714934):12) 10-27 17:47:46.706 15044 15507 W AsyncOperation: at cljx.run(:com.google.android.gms@224113024@22.41.13 (100300-480714934):2) 10-27 17:47:46.706 15044 15507 W AsyncOperation: at ablo.c(:com.google.android.gms@224113024@22.41.13 (100300-480714934):6) 10-27 17:47:46.706 15044 15507 W AsyncOperation: at ablo.run(:com.google.android.gms@224113024@22.41.13 (100300-480714934):7) 10-27 17:47:46.706 15044 15507 W AsyncOperation: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 10-27 17:47:46.706 15044 15507 W AsyncOperation: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 10-27 17:47:46.706 15044 15507 W AsyncOperation: at abqt.run(:com.google.android.gms@224113024@22.41.13 (100300-480714934):0) 10-27 17:47:46.706 15044 15507 W AsyncOperation: at java.lang.Thread.run(Thread.java:764) 10-27 17:47:46.706 15044 15507 W AsyncOperation: Caused by: zcm: Error retrieving oauth token 10-27 17:47:46.706 15044 15507 W AsyncOperation: at zib.c(:com.google.android.gms@224113024@22.41.13 (100300 ... 10-27 17:47:46.706 15044 15507 W AsyncOperation: Caused by: com.google.android.gms.auth.UserRecoverableAuthException: BadAuthentication


6. Not being handle the exception `com.google.android.gms.auth.UserRecoverableAuthException` leads to the intent to never return the control the app and users get on a bad situation where the are waiting the activity to start or display an error message.
neilpatrickadams commented 1 year ago

I'm also seeing this issue with 2 reports in the last couple of days - users unable to get into my app.

Device 1 (Confirmed): Samsung S21+ 5G / Android 12 / Google Play system June 1 2022 Device 2 (Reported not confirmed): Galaxy S10 / Android 12

Environment is: implementation platform('com.google.firebase:firebase-bom:30.3.2') implementation 'com.firebaseui:firebase-ui-auth:8.0.2' implementation 'com.firebaseui:firebase-ui-firestore:6.1.0' implementation 'com.firebaseui:firebase-ui-storage:6.4.0' (with older versions of firestore and storage, I upgraded auth hoping that would address the issue)

    List<AuthUI.IdpConfig> providers = Arrays.asList(
            new AuthUI.IdpConfig.GoogleBuilder().build()
    );

    // Create and launch sign-in intent
    startActivityForResult(
            AuthUI.getInstance()
                    .createSignInIntentBuilder()
                    .setAvailableProviders(providers)
                    .build(),
            RC_SIGN_IN);

I had access to device 1 for a couple hours and was able to get some logs and try a few things.

Any suggestions for workarounds?

Some snippets of the logs:

2022-10-28 20:20:25.081 20493-20756/? E/earn: ~~~ Channel {0} was not shutdown properly!!! ~~~ Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true. java.lang.RuntimeException: ManagedChannel allocation site at earm.(:com.google.android.gms@224212044@22.42.12 (190400-481949630):3) at earn.(:com.google.android.gms@224212044@22.42.12 (190400-481949630):2) ... at java.lang.Thread.run(Thread.java:920) 2022-10-28 20:20:25.082 1308-1541/? I/libprocessgroup: Successfully killed process cgroup uid 1000 pid 19150 in 11ms 2022-10-28 20:20:25.089 20654-22802/? E/AuthPII: [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/login_manager ywn: Long live credential not available. at kyl.a(:com.google.android.gms@224212044@22.42.12 (190400-481949630):8) at kyr.c(:com.google.android.gms@224212044@22.42.12 (190400-481949630):3) ... 2022-10-28 20:20:25.089 20654-22802/? E/AuthPII: Message is Long live credential not available. ywn: Long live credential not available. at kyl.a(:com.google.android.gms@224212044@22.42.12 (190400-481949630):8) at kyr.c(:com.google.android.gms@224212044@22.42.12 (190400-481949630):3) ... 2022-10-28 20:20:25.089 20654-22802/? W/Auth: [GetToken] GetToken failed with status code: BadAuthentication 2022-10-28 20:20:25.095 20493-20756/? W/Auth: [GoogleAuthUtil] isUserRecoverableError status: BAD_AUTHENTICATION 2022-10-28 20:20:25.097 20654-31475/? E/AuthPII: [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/login_manager ywn: Long live credential not available. at kyl.a(:com.google.android.gms@224212044@22.42.12 (190400-481949630):8) at kyr.c(:com.google.android.gms@224212044@22.42.12 (190400-481949630):3) ... 2022-10-28 20:20:25.097 20654-31475/? E/AuthPII: Message is Long live credential not available. ywn: Long live credential not available. at kyl.a(:com.google.android.gms@224212044@22.42.12 (190400-481949630):8) at kyr.c(:com.google.android.gms@224212044@22.42.12 (190400-481949630):3) ... 2022-10-28 20:20:25.108 20493-20756/? W/AsyncOperation: operation=List, opStatusCode=11005 [CONTEXT service_id=80 ] OperationException[Status{statusCode=Error listing passwords, resolution=PendingIntent{2fb9331: android.os.BinderProxy@4dcca16}}] at xox.c(:com.google.android.gms@224212044@22.42.12 (190400-481949630):14) at xox.d(:com.google.android.gms@224212044@22.42.12 (190400-481949630):16) .... Caused by: xny: Error listing passwords at xrx.i(:com.google.android.gms@224212044@22.42.12 (190400-481949630):31) at xtn.a(:com.google.android.gms@224212044@22.42.12 (190400-481949630):45)

zjamshidi commented 1 year ago

@thatfiredev Any update on this issue?

neilpatrickadams commented 1 year ago

Any updates on a work-around or fix for this issue?

It's a gating issue for us as we have users unable to access the app/their data.

Thanks!

danielrrv commented 1 year ago

After @jftabord reproduced the bug on a demoFirebaseUI app and after we noticed the request was trying to access to credential at the Google Play Services/ Smart Lock https://github.com/firebase/FirebaseUI-Android/blob/5b6c9f01f5a674d754d8e9b1242197fe040086e7/auth/src/main/java/com/firebase/ui/auth/data/remote/SignInKickstarter.java#L97-L121 We have found:

Deactive the Google Smart Lock .setIsSmartLockEnabled(false) (true by default) has solved the problem for our users. Here why: The if block statement has two conditions; I will omit the willRequestCredentials because is normally true. The other one getArguments().enableCredentials is set by the setIsSmartLockEnabled@AuthUI.java which is also set by the Intent created by our apps.

So being the if block statement false the execution goes down through the method startAuthMethodChoice that somehow returns the control to your app always.

So basically, for some users, Smart Lock might fail and the Intent is not giving back control to the app that has launched it (spinner rolling non-stop) due to failures in the request.

neilpatrickadams commented 1 year ago

@danielrrv Thanks for the info.

If the user disables smart lock is this a workaround?

Are you planning on pushing this change to FirebaseUI-Android , or did you just make the change for your app locally?

Thanks!

danielrrv commented 1 year ago

@neilpatrickadams just update your app and give a try.

com.firebase.ui.auth.AuthUI.getInstance()
...
.setIsSmartLockEnabled(false)
.setAlwaysShowSignInMethodScreen(true)
...
.build();
TOrnelas commented 1 year ago

After @jftabord reproduced the bug on a demoFirebaseUI app and after we noticed the request was trying to access to credential at the Google Play Services/ Smart Lock

https://github.com/firebase/FirebaseUI-Android/blob/5b6c9f01f5a674d754d8e9b1242197fe040086e7/auth/src/main/java/com/firebase/ui/auth/data/remote/SignInKickstarter.java#L97-L121

We have found: Deactive the Google Smart Lock .setIsSmartLockEnabled(false) (true by default) has solved the problem for our users. Here why: The if block statement has two conditions; I will omit the willRequestCredentials because is normally true. The other one getArguments().enableCredentials is set by the setIsSmartLockEnabled@AuthUI.java which is also set by the Intent created by our apps.

So being the if block statement false the execution goes down through the method startAuthMethodChoice that somehow returns the control to your app always.

So basically, for some users, Smart Lock might fail and the Intent is not giving back control to the app that has launched it (spinner rolling non-stop) due to failures in the request.

Life saver!

neilpatrickadams commented 1 year ago

@neilpatrickadams just update your app and give a try.

com.firebase.ui.auth.AuthUI.getInstance()
...
.setIsSmartLockEnabled(false)
.setAlwaysShowSignInMethodScreen(true)
...
.build();

Thanks this worked (just needed setIsSmartLockEnabled(false)).

LordChunder commented 1 year ago

when smart lock is enabled and used to launch the sign in flow in 8.0.2 when there is no internet connection it runs off into a loop in the sign in activity and just gives a dim screen. Without smart lock when there is no internet connection the sign in provider flow pops up and reports snackbars check your internet connection as expected.

paoloviafora commented 1 year ago

same issue on Samsung Galaxy tab A image

image

when launches the sign-in intent i get stuck...with infinite loading (waiting 10 minutes and nothing appear).

in my code: .setIsSmartLockEnabled(true) .setAlwaysShowSignInMethodScreen(true)

.gradle:

implementation platform('com.google.firebase:firebase-bom:31.1.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-config'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-storage'
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-inappmessaging-display'

implementation 'com.firebaseui:firebase-ui-auth:8.0.2'
implementation 'com.firebaseui:firebase-ui-storage:8.0.2'

implementation 'com.google.android.gms:play-services-auth:20.4.0'

.... ... ....

Deepanshusuman commented 1 year ago

when i click on back button

A sign-in error occurred.
                 v4.j: Unknown error
                    at com.firebase.ui.auth.KickoffActivity.onActivityResult(SourceFile:66)
                    at android.app.Activity.dispatchActivityResult(Activity.java:8316)
                    at android.app.ActivityThread.deliverResults(ActivityThread.java:5237)
                    at android.app.ActivityThread.handleSendResult(ActivityThread.java:5285)
                    at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
                    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
                    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2251)
                    at android.os.Handler.dispatchMessage(Handler.java:106)
                    at android.os.Looper.loop(Looper.java:233)
                    at android.app.ActivityThread.main(ActivityThread.java:8068)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
Deepanshusuman commented 1 year ago

https://github.com/firebase/FirebaseUI-Android/issues/2067

kajfik commented 1 year ago

If you have recently upgraded to AGP 8.0 or if you have enabled android.enableR8.fullMode=true then this might fix it for you: https://github.com/firebase/firebase-android-sdk/issues/2124#issuecomment-920922929