Search in sources :

Example 21 with FirebaseUiException

use of com.firebase.ui.auth.FirebaseUiException in project FirebaseUI-Android by firebase.

the class GoogleSignInHandler method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (requestCode != RequestCodes.GOOGLE_PROVIDER) {
        return;
    }
    try {
        GoogleSignInAccount account = GoogleSignIn.getSignedInAccountFromIntent(data).getResult(ApiException.class);
        setResult(Resource.forSuccess(createIdpResponse(account)));
    } catch (ApiException e) {
        if (e.getStatusCode() == CommonStatusCodes.INVALID_ACCOUNT) {
            // If we get INVALID_ACCOUNT, it means the pre-set account was not available on the
            // device so set the email to null and launch the sign-in picker.
            mEmail = null;
            start();
        } else if (e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CURRENTLY_IN_PROGRESS) {
            // Hack for https://github.com/googlesamples/google-services/issues/345
            // Google remembers the account so the picker doesn't appear twice for the user.
            start();
        } else if (e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CANCELLED) {
            setResult(Resource.forFailure(new UserCancellationException()));
        } else {
            if (e.getStatusCode() == CommonStatusCodes.DEVELOPER_ERROR) {
                Log.w(TAG, "Developer error: this application is misconfigured. " + "Check your SHA1 and package name in the Firebase console.");
            }
            setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.PROVIDER_ERROR, "Code: " + e.getStatusCode() + ", message: " + e.getMessage())));
        }
    }
}
Also used : GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) UserCancellationException(com.firebase.ui.auth.data.model.UserCancellationException) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) ApiException(com.google.android.gms.common.api.ApiException)

Example 22 with FirebaseUiException

use of com.firebase.ui.auth.FirebaseUiException in project FirebaseUI-Android by firebase.

the class EmailLinkCatcherActivity method initHandler.

private void initHandler() {
    mHandler = new ViewModelProvider(this).get(EmailLinkSignInHandler.class);
    mHandler.init(getFlowParams());
    mHandler.getOperation().observe(this, new ResourceObserver<IdpResponse>(this) {

        @Override
        protected void onSuccess(@NonNull IdpResponse response) {
            finish(RESULT_OK, response.toIntent());
        }

        @Override
        protected void onFailure(@NonNull final Exception e) {
            if (e instanceof UserCancellationException) {
                finish(RESULT_CANCELED, null);
            } else if (e instanceof FirebaseAuthAnonymousUpgradeException) {
                IdpResponse res = ((FirebaseAuthAnonymousUpgradeException) e).getResponse();
                finish(RESULT_CANCELED, new Intent().putExtra(ExtraConstants.IDP_RESPONSE, res));
            } else if (e instanceof FirebaseUiException) {
                int errorCode = ((FirebaseUiException) e).getErrorCode();
                if (errorCode == ErrorCodes.EMAIL_LINK_WRONG_DEVICE_ERROR || errorCode == ErrorCodes.INVALID_EMAIL_LINK_ERROR || errorCode == ErrorCodes.EMAIL_LINK_DIFFERENT_ANONYMOUS_USER_ERROR) {
                    buildAlertDialog(errorCode).show();
                } else if (errorCode == ErrorCodes.EMAIL_LINK_PROMPT_FOR_EMAIL_ERROR || errorCode == ErrorCodes.EMAIL_MISMATCH_ERROR) {
                    startErrorRecoveryFlow(RequestCodes.EMAIL_LINK_PROMPT_FOR_EMAIL_FLOW);
                } else if (errorCode == ErrorCodes.EMAIL_LINK_CROSS_DEVICE_LINKING_ERROR) {
                    startErrorRecoveryFlow(RequestCodes.EMAIL_LINK_CROSS_DEVICE_LINKING_FLOW);
                }
            } else if (e instanceof FirebaseAuthInvalidCredentialsException) {
                startErrorRecoveryFlow(RequestCodes.EMAIL_LINK_PROMPT_FOR_EMAIL_FLOW);
            } else {
                finish(RESULT_CANCELED, IdpResponse.getErrorIntent(e));
            }
        }
    });
}
Also used : UserCancellationException(com.firebase.ui.auth.data.model.UserCancellationException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) EmailLinkSignInHandler(com.firebase.ui.auth.viewmodel.email.EmailLinkSignInHandler) Intent(android.content.Intent) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) UserCancellationException(com.firebase.ui.auth.data.model.UserCancellationException) FirebaseAuthAnonymousUpgradeException(com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthAnonymousUpgradeException(com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException) ViewModelProvider(androidx.lifecycle.ViewModelProvider) IdpResponse(com.firebase.ui.auth.IdpResponse)

Aggregations

FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)22 IdpResponse (com.firebase.ui.auth.IdpResponse)16 Resource (com.firebase.ui.auth.data.model.Resource)9 FirebaseAuthAnonymousUpgradeException (com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException)8 ViewModelProvider (androidx.lifecycle.ViewModelProvider)6 Test (org.junit.Test)6 InOrder (org.mockito.InOrder)6 User (com.firebase.ui.auth.data.model.User)5 Intent (android.content.Intent)4 AuthUI (com.firebase.ui.auth.AuthUI)4 UserCancellationException (com.firebase.ui.auth.data.model.UserCancellationException)4 FirebaseAuthError (com.firebase.ui.auth.util.FirebaseAuthError)4 AuthOperationManager (com.firebase.ui.auth.util.data.AuthOperationManager)4 FirebaseAuthException (com.google.firebase.auth.FirebaseAuthException)4 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)4 Application (android.app.Application)3 TextView (android.widget.TextView)3 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 RestrictTo (androidx.annotation.RestrictTo)3