FirebaseUI-Android icon indicating copy to clipboard operation
FirebaseUI-Android copied to clipboard

Not handling error: "FacebookProvider: Error logging in with Facebook. User logged in as different Facebook user"

Open joknu1 opened this issue 7 years ago • 8 comments

  • Android device: HTC A9
  • Android OS version: 6.0
  • Google Play Services version: 3.1.0
  • Firebase/Play Services SDK version: 11.0.4
  • FirebaseUI version: 2.3.0
  • Facebook-android-sdk: 4.25.0

Firebase UI does not handle "E/FacebookProvider: Error logging in with Facebook. User logged in as different Facebook user."

Steps to reproduce:

  1. Use native Facebook app to log out current user A
  2. Launch firebase-ui and try log in in with another facebook user B

Expected: firebase-ui should display any errors, or onActivityResult should be called with some error

Actual: Nothing happens. Logcat prints "E/FacebookProvider: Error logging in with Facebook. User logged in as different Facebook user."

This use case might be quite rare, but it is confusing for customer to not get any feedback.

joknu1 avatar Aug 24 '17 10:08 joknu1

This comes from the `onError callback here: https://github.com/firebase/FirebaseUI-Android/blob/bee4c1a9f6e4e872670796d30bc94e7a396751e3/auth/src/main/java/com/firebase/ui/auth/provider/FacebookProvider.java#L173

It does call onFailure().

@joknu1 what happens in this case exactly? Does it return back to the sign-in button screen?

samtstern avatar Aug 24 '17 16:08 samtstern

Yes. It looks like it actually never leaves the sign-in button screen.

Or maybe on first attempt I got to select Facebook account to use before returning to sign-in button screen. On sequential attempts I do not get to select Facebook account. From a user perspective, the Facebook button then appears non functional.

joknu1 avatar Aug 24 '17 16:08 joknu1

What happened with this?, I'm facing the same issue and I couldn't find a solution :/

Jackson350 avatar Mar 22 '18 18:03 Jackson350

Hi,

This issue is still open? Can I help?

Thanks.

ericalima avatar Mar 08 '19 19:03 ericalima

@ericalima if you have an idea of what's wrong and how to fix it we'd love your help! We are always looking for new contributors.

samtstern avatar Mar 08 '19 19:03 samtstern

I will give a try! Thanks!

ericalima avatar Mar 08 '19 19:03 ericalima

I will give a try! Thanks!

ericalima avatar Mar 09 '19 15:03 ericalima

Hi @samtstern @SUPERCILEX ! I believe this issue is not related with Firebase-UI, but with Facebook Auth Library. It checks in AccessToken class if:

/**
     * Returns whether the current {@link AccessToken} is active or not.
     *
     * @return true if the current AccessToken exists and has not expired; false, otherwise.
     */
 public static boolean isCurrentAccessTokenActive() {
             final AccessToken accessToken = AccessTokenManager.getInstance().getCurrentAccessToken();
              return accessToken != null && !accessToken.isExpired();
    };

The thing is, in our case the Token is not expired yet and is also not null. But it has been removed access as you can see in the screenshot below.

image

Since we return true in isCurrentAccessTokenActive() we instantiate our AccessTokenAppIdPair wrongly here:

// If we have a session and the appId passed is null or matches the session's app ID:
        if (AccessToken.isCurrentAccessTokenActive() &&
                (applicationId == null || applicationId.equals(accessToken.getApplicationId()))
                ) {
            accessTokenAppId = new AccessTokenAppIdPair(accessToken);
        } else {
            // If no app ID passed, get it from the manifest:
            if (applicationId == null) {
                applicationId = Utility.getMetadataApplicationId(
                        `FacebookSdk.getApplicationContext());
            }
            accessTokenAppId = new AccessTokenAppIdPair(null, applicationId);
        }

The current implementation works fine if after the token has been removed access the user tries to log in with the same account, but it breaks when the user tries it with a different account.


Solution: isCurrentAccessTokenActive() should return true only if accessToken != null && !accessToken.isExpired() && !accessToken.toTokenString().equals("ACCESS_TOKEN_REMOVED");

felipe-gouveia avatar May 09 '19 18:05 felipe-gouveia