Firebaseui-android: Back button during Facebook/Twitter flow shows 'Provider Error'

Created on 20 Jan 2019  路  23Comments  路  Source: firebase/FirebaseUI-Android

Step 1: Are you in the right place?

I think I am :)

Step 2: Describe your environment

All android devices

implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'

Step 3: Describe the problem:

When user try to sing in via firebase auth UI, and when user click on facebook or twitter provider and if he press android back he get toast message "Provider error". If he continue to singin via facebook or twitter it works but if user press bach he get error message. All is configured.

Steps to reproduce:

download test project from this link and try it: https://drive.google.com/file/d/1viGBLvyoMf5Tyedffuo0ZY8sMBPn6UqK/view?usp=sharing

For facebook provider all is configured, for twitter in this test project it isn't and you don't get for twitter provider toast error, only for facebook ...

Observed Results:

User see wrong toast error message

Expected Results:

there should not be any toast message when user goes back to previous screen

auth fix-implemented bug

Most helpful comment

@ustrajunior I haven't had time to look at it yet, if you want to try please do! I'd be happy to review the PR

All 23 comments

@nole87 just to make sure I understand, is this the correct step sequence to reproduce?

  1. Start sign in with Facebook (or Twitter)
  2. At some point in the middle of the sign in flow, press back
  3. FirebaseUI displays a "Provider Error" toast when it should say "Canceled" or nothing

when facebook or twitter is open and user can enter username and password than if user press back he get error message. Download from this link short clip: https://drive.google.com/file/d/1KGl0MnOW-M4HntMr9ZLi5n56bTkaGDLP/view?usp=sharing

Thanks @nole87 that's a clear reproduction of the bug!

Hey.

There is someone working on this issue? If not, I'd like to give a try.

Thanks.

@ustrajunior I haven't had time to look at it yet, if you want to try please do! I'd be happy to review the PR

Good afternoon!

I am developing an application that starts with an activity for user authentication through email, Google, Facebook and Twitter, and I get the same error as @nole87 .

Additionally, when the application is running, I get the following errors:

Email / Google:
E/AuthUI: A sign-in error occurred.
com.firebase.ui.auth.data.model.UserCancellationException: Unknown error

_NOTE: in the case of Google, the error appears three times._

Facebook:
E/AuthUI: A sign-in error occurred.
com.firebase.ui.auth.FirebaseUiException: Provider error
Caused by: null

_NOTE: the error appears three times._

Twitter:
_First error:_
E/Twitter: Authorization completed with an error
com.twitter.sdk.android.core.TwitterAuthException: Authorization failed, request was canceled.

_Second error:_
E/AuthUI: A sign-in error occurred.
com.firebase.ui.auth.FirebaseUiException: Provider error
Caused by: com.twitter.sdk.android.core.TwitterAuthException: Authorization failed, request was canceled.

_NOTE: the second error appears three times._

Does the same behavior occur to you @nole87, @ustrajunior ?

Hello,
I'm getting this same problem when going back (with button) or canceling both Twitter and Facebook logins.
Any updates or known workarounds to avoid the error Toast?
Thanks.

This week I will be working on this issue to try to find a solution. Hope to have something to the end of this week.

@ustrajunior nice! Thanks for the update.

@samtstern I believe I found the problem.

For facebook callback, the onCancel method handles the cancel calling the onError method here: L112.

I changed the onCancel method to this:

public void onCancel() {
    setResult(Resource.<IdpResponse>forFailure(new FirebaseUiException(
        ErrorCodes.SIGNIN_CANCELED, new FacebookException())));
}

and I had to add SIGNIN_CANCELED to the ErrorCodes.java file.

With this change, instead of "Provider error" it will show "The sign in process was canceled".

The onError will continue to act the same way.

For Twitter, it's a little different because there is no onCancel, just onFailure. I'm not sure, yet, if there is an easy way to differentiate an error of a cancel.

For Google, not sure yet. I'm having problems to reproduce the error, for me, occurs an error but it is not shown on the UI.

What do you think about this solution? If you think it's ok, I will continue following this path.

Only facebook and twitter providers show toast msg when user cancel auth process. In my opinion best if possible no toast msg at all but if not possible or too much time it takes to resolve than some appropriate msg is good enough ...

@ustrajunior that definitely seems like the right start to a solution!

Going to move this to the next release milestone (4.4.0) to give @ustrajunior more time to come up with a solution.

Thanks, @samtstern. Last week was crazy for me so I was not able to work on the issue. Til the end of this week, I hope to have a more concrete solution.

@ustrajunior. Have you been able to come up with a solution now?

I think I have come up with a solution. I attached a snippet for the Facebook callback in the FacebookSignInHandler class . In the onCancel method, you can return a UserCancellationException instead.

 @Override
        public void onCancel() {
            setResult(Resource.<IdpResponse>forFailure(new UserCancellationException()));
        }

studio64_2019-05-07_07-56-35

For Google sign-in you can check the status code in onActivityResult of the GoogleSignInHandler class:

if (e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CANCELLED) {
                    Timber.e(e);
                    setResult(Resource.<IdpResponse>forFailure(new UserCancellationException()));
                }

studio64_2019-05-07_08-01-18

The same idea can be applied to the other providers...

Hey @KryptKode. Unfortunately, I did not have the time to work on this issue. You can get it if you want.

Hi @samtstern I'm carrying on @ustrajunior 's work here since he just became a parent, yupi! :) We are currently doing a project at Universidade do Porto and this issue is part of an assignment of contributing to opensource. I believe @ustrajunior already solves the issue in the reply below, since https://github.com/firebase/FirebaseUI-Android/pull/1627 removes TwitterSignInHandler and it doesn't make sense to temper with it for now.

Also, just a tweek into his comment, since the toast message is an alert to the user, it makes more sense to display the message "The sign in process was canceled" to the user and to the developer show "The sign in process was canceled by the user".

@KryptKode regarding the Google SignIn there is currently not issue with the back button, so don't think it's necessary. But your solution to the Facebook is nice and almost the same as @ustrajunior, but I think that since we already have a FirebaseUiException which is overloaded to support the exceptions message we should use it.

I have submitted a pull request with the solution in https://github.com/firebase/FirebaseUI-Android/pull/1630

@samtstern I believe I found the problem.

For facebook callback, the onCancel method handles the cancel calling the onError method here: L112.

I changed the onCancel method to this:

public void onCancel() {
  setResult(Resource.<IdpResponse>forFailure(new FirebaseUiException(
      ErrorCodes.SIGNIN_CANCELED, new FacebookException())));
}

and I had to add SIGNIN_CANCELED to the ErrorCodes.java file.

With this change, instead of "Provider error" it will show "The sign in process was canceled".

The onError will continue to act the same way.

For Twitter, it's a little different because there is no onCancel, just onFailure. I'm not sure, yet, if there is an easy way to differentiate an error of a cancel.

For Google, not sure yet. I'm having problems to reproduce the error, for me, occurs an error but it is not shown on the UI.

What do you think about this solution? If you think it's ok, I will continue following this path.

@felipe-gouveia thanks for the PR and @ustrajunior congrats on becoming a parent! This week I am super busy with Google I/O so I will get to this as soon as I can.

Thanks, @samtstern. Time is something rare, for me, right now ;D

Facebook will be fixed in 5.0.0 thanks to @ustrajunior and @felipe-gouveia, and we can work on Twitter for 5.0.1

Facebook will be fixed in 5.0.0 thanks to @ustrajunior and @felipe-gouveia, and we can work on Twitter for 5.0.1

Hi @samtstern, @ustrajunior, and @felipe-gouveia, I still get the error in 5.0.0. Is there something I am doing wrong or is it yet to be fixed? Thanks for the good work.

The fix for this issue has been released in version 6.2.1

Was this page helpful?
0 / 5 - 0 ratings