Search in sources :

Example 1 with FirebaseAuthInvalidUserException

use of com.google.firebase.auth.FirebaseAuthInvalidUserException in project FirebaseUI-Android by firebase.

the class RecoverPasswordActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fui_forgot_password_layout);
    mHandler = new ViewModelProvider(this).get(RecoverPasswordHandler.class);
    mHandler.init(getFlowParams());
    mHandler.getOperation().observe(this, new ResourceObserver<String>(this, R.string.fui_progress_dialog_sending) {

        @Override
        protected void onSuccess(@NonNull String email) {
            mEmailInputLayout.setError(null);
            showEmailSentDialog(email);
        }

        @Override
        protected void onFailure(@NonNull Exception e) {
            if (e instanceof FirebaseAuthInvalidUserException || e instanceof FirebaseAuthInvalidCredentialsException) {
                // No FirebaseUser exists with this email address, show error.
                mEmailInputLayout.setError(getString(R.string.fui_error_email_does_not_exist));
            } else {
                // Unknown error
                mEmailInputLayout.setError(getString(R.string.fui_error_unknown));
            }
        }
    });
    mProgressBar = findViewById(R.id.top_progress_bar);
    mSubmitButton = findViewById(R.id.button_done);
    mEmailInputLayout = findViewById(R.id.email_layout);
    mEmailEditText = findViewById(R.id.email);
    mEmailFieldValidator = new EmailFieldValidator(mEmailInputLayout);
    String email = getIntent().getStringExtra(ExtraConstants.EMAIL);
    if (email != null) {
        mEmailEditText.setText(email);
    }
    ImeHelper.setImeOnDoneListener(mEmailEditText, this);
    mSubmitButton.setOnClickListener(this);
    TextView footerText = findViewById(R.id.email_footer_tos_and_pp_text);
    PrivacyDisclosureUtils.setupTermsOfServiceFooter(this, getFlowParams(), footerText);
}
Also used : RecoverPasswordHandler(com.firebase.ui.auth.viewmodel.email.RecoverPasswordHandler) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) EmailFieldValidator(com.firebase.ui.auth.util.ui.fieldvalidators.EmailFieldValidator) TextView(android.widget.TextView) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 2 with FirebaseAuthInvalidUserException

use of com.google.firebase.auth.FirebaseAuthInvalidUserException in project FirebaseUI-Android by firebase.

the class SignInKickstarter method handleCredential.

private void handleCredential(final Credential credential) {
    String id = credential.getId();
    String password = credential.getPassword();
    if (TextUtils.isEmpty(password)) {
        String identity = credential.getAccountType();
        if (identity == null) {
            startAuthMethodChoice();
        } else {
            redirectSignIn(ProviderUtils.accountTypeToProviderId(credential.getAccountType()), id);
        }
    } else {
        final IdpResponse response = new IdpResponse.Builder(new User.Builder(EmailAuthProvider.PROVIDER_ID, id).build()).build();
        setResult(Resource.forLoading());
        getAuth().signInWithEmailAndPassword(id, password).addOnSuccessListener(result -> handleSuccess(response, result)).addOnFailureListener(e -> {
            if (e instanceof FirebaseAuthInvalidUserException || e instanceof FirebaseAuthInvalidCredentialsException) {
                // In this case the credential saved in SmartLock was not
                // a valid credential, we should delete it from SmartLock
                // before continuing.
                GoogleApiUtils.getCredentialsClient(getApplication()).delete(credential);
            }
            startAuthMethodChoice();
        });
    }
}
Also used : ProviderUtils(com.firebase.ui.auth.util.data.ProviderUtils) Bundle(android.os.Bundle) EmailLinkCatcherActivity(com.firebase.ui.auth.ui.email.EmailLinkCatcherActivity) EMAIL_LINK_PROVIDER(com.firebase.ui.auth.AuthUI.EMAIL_LINK_PROVIDER) PhoneActivity(com.firebase.ui.auth.ui.phone.PhoneActivity) NonNull(androidx.annotation.NonNull) User(com.firebase.ui.auth.data.model.User) IntentRequiredException(com.firebase.ui.auth.data.model.IntentRequiredException) Intent(android.content.Intent) Resource(com.firebase.ui.auth.data.model.Resource) ExtraConstants(com.firebase.ui.auth.util.ExtraConstants) GoogleApiUtils(com.firebase.ui.auth.util.GoogleApiUtils) PhoneAuthProvider(com.google.firebase.auth.PhoneAuthProvider) Task(com.google.android.gms.tasks.Task) ArrayList(java.util.ArrayList) GoogleAuthProvider(com.google.firebase.auth.GoogleAuthProvider) AuthMethodPickerActivity(com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity) SingleSignInActivity(com.firebase.ui.auth.ui.idp.SingleSignInActivity) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) AuthUI(com.firebase.ui.auth.AuthUI) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) EmailActivity(com.firebase.ui.auth.ui.email.EmailActivity) UserCancellationException(com.firebase.ui.auth.data.model.UserCancellationException) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) SignInViewModelBase(com.firebase.ui.auth.viewmodel.SignInViewModelBase) TextUtils(android.text.TextUtils) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) CredentialRequestResponse(com.google.android.gms.auth.api.credentials.CredentialRequestResponse) CredentialRequest(com.google.android.gms.auth.api.credentials.CredentialRequest) CommonStatusCodes(com.google.android.gms.common.api.CommonStatusCodes) List(java.util.List) Credential(com.google.android.gms.auth.api.credentials.Credential) Nullable(androidx.annotation.Nullable) EmailAuthProvider(com.google.firebase.auth.EmailAuthProvider) Application(android.app.Application) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) RequestCodes(com.firebase.ui.auth.viewmodel.RequestCodes) AuthResult(com.google.firebase.auth.AuthResult) ErrorCodes(com.firebase.ui.auth.ErrorCodes) Activity(android.app.Activity) ApiException(com.google.android.gms.common.api.ApiException) IdpResponse(com.firebase.ui.auth.IdpResponse) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) User(com.firebase.ui.auth.data.model.User) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 3 with FirebaseAuthInvalidUserException

use of com.google.firebase.auth.FirebaseAuthInvalidUserException in project FirebaseUI-Android by firebase.

the class SocialProviderResponseHandler method startSignIn.

public void startSignIn(@NonNull final IdpResponse response) {
    if (!response.isSuccessful() && !response.isRecoverableErrorResponse()) {
        setResult(Resource.forFailure(response.getError()));
        return;
    }
    if (isEmailOrPhoneProvider(response.getProviderType())) {
        throw new IllegalStateException("This handler cannot be used with email or phone providers");
    }
    setResult(Resource.forLoading());
    // a credential made from the id token/access token cannot be used to sign-in.
    if (response.hasCredentialForLinking()) {
        handleGenericIdpLinkingFlow(response);
        return;
    }
    final AuthCredential credential = ProviderUtils.getAuthCredential(response);
    AuthOperationManager.getInstance().signInAndLinkWithCredential(getAuth(), getArguments(), credential).continueWithTask(new ProfileMerger(response)).addOnSuccessListener(result -> handleSuccess(response, result)).addOnFailureListener(e -> {
        // For some reason disabled users can hit FirebaseAuthUserCollisionException
        // so we have to handle this special case.
        boolean isDisabledUser = (e instanceof FirebaseAuthInvalidUserException);
        if (e instanceof FirebaseAuthException) {
            FirebaseAuthException authEx = (FirebaseAuthException) e;
            FirebaseAuthError fae = FirebaseAuthError.fromException(authEx);
            if (fae == FirebaseAuthError.ERROR_USER_DISABLED) {
                isDisabledUser = true;
            }
        }
        if (isDisabledUser) {
            setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.ERROR_USER_DISABLED)));
        } else if (e instanceof FirebaseAuthUserCollisionException) {
            final String email = response.getEmail();
            if (email == null) {
                setResult(Resource.forFailure(e));
                return;
            }
            // There can be a collision due to:
            // CASE 1: Anon user signing in with a credential that belongs to an
            // existing user.
            // CASE 2: non - anon user signing in with a credential that does not
            // belong to an existing user, but the email matches an existing user
            // that has another social IDP. We need to link this new IDP to this
            // existing user.
            // CASE 3: CASE 2 with an anonymous user. We link the new IDP to the
            // same account before handling invoking a merge failure.
            ProviderUtils.fetchSortedProviders(getAuth(), getArguments(), email).addOnSuccessListener(providers -> {
                if (providers.contains(response.getProviderType())) {
                    // Case 1
                    handleMergeFailure(credential);
                } else if (providers.isEmpty()) {
                    setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.DEVELOPER_ERROR, "No supported providers.")));
                } else {
                    // Case 2 & 3 - we need to link
                    startWelcomeBackFlowForLinking(providers.get(0), response);
                }
            }).addOnFailureListener(e1 -> setResult(Resource.forFailure(e1)));
        }
    });
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) WelcomeBackIdpPrompt(com.firebase.ui.auth.ui.idp.WelcomeBackIdpPrompt) ProviderUtils(com.firebase.ui.auth.util.data.ProviderUtils) ProfileMerger(com.firebase.ui.auth.data.remote.ProfileMerger) EMAIL_LINK_PROVIDER(com.firebase.ui.auth.AuthUI.EMAIL_LINK_PROVIDER) NonNull(androidx.annotation.NonNull) User(com.firebase.ui.auth.data.model.User) IntentRequiredException(com.firebase.ui.auth.data.model.IntentRequiredException) Intent(android.content.Intent) Resource(com.firebase.ui.auth.data.model.Resource) PhoneAuthProvider(com.google.firebase.auth.PhoneAuthProvider) RestrictTo(androidx.annotation.RestrictTo) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) SignInViewModelBase(com.firebase.ui.auth.viewmodel.SignInViewModelBase) TextUtils(android.text.TextUtils) AuthOperationManager(com.firebase.ui.auth.util.data.AuthOperationManager) FirebaseAuthError(com.firebase.ui.auth.util.FirebaseAuthError) AuthCredential(com.google.firebase.auth.AuthCredential) List(java.util.List) Nullable(androidx.annotation.Nullable) EmailAuthProvider(com.google.firebase.auth.EmailAuthProvider) Application(android.app.Application) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) WelcomeBackEmailLinkPrompt(com.firebase.ui.auth.ui.email.WelcomeBackEmailLinkPrompt) FirebaseAuthException(com.google.firebase.auth.FirebaseAuthException) RequestCodes(com.firebase.ui.auth.viewmodel.RequestCodes) AuthResult(com.google.firebase.auth.AuthResult) ErrorCodes(com.firebase.ui.auth.ErrorCodes) Activity(android.app.Activity) IdpResponse(com.firebase.ui.auth.IdpResponse) WelcomeBackPasswordPrompt(com.firebase.ui.auth.ui.email.WelcomeBackPasswordPrompt) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) FirebaseAuthError(com.firebase.ui.auth.util.FirebaseAuthError) ProfileMerger(com.firebase.ui.auth.data.remote.ProfileMerger) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) FirebaseAuthException(com.google.firebase.auth.FirebaseAuthException)

Example 4 with FirebaseAuthInvalidUserException

use of com.google.firebase.auth.FirebaseAuthInvalidUserException in project FirebaseUI-Android by firebase.

the class RecoverPasswordActivity method next.

private void next(final String email) {
    mActivityHelper.getFirebaseAuth().sendPasswordResetEmail(email).addOnFailureListener(new TaskFailureLogger(TAG, "Error sending password reset email")).addOnSuccessListener(new OnSuccessListener<Void>() {

        @Override
        public void onSuccess(Void aVoid) {
            mActivityHelper.dismissDialog();
            RecoveryEmailSentDialog.show(email, getSupportFragmentManager());
        }
    }).addOnFailureListener(this, new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            mActivityHelper.dismissDialog();
            if (e instanceof FirebaseAuthInvalidUserException) {
                // No FirebaseUser exists with this email address, show error.
                mEmailEditText.setError(getString(R.string.error_email_does_not_exist));
            }
        }
    });
}
Also used : FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException)

Example 5 with FirebaseAuthInvalidUserException

use of com.google.firebase.auth.FirebaseAuthInvalidUserException in project FirebaseUI-Android by firebase.

the class AuthUI method delete.

/**
 * Delete the use from FirebaseAuth and delete any associated credentials from the Credentials
 * API. Returns a {@link Task} that succeeds if the Firebase Auth user deletion succeeds and
 * fails if the Firebase Auth deletion fails. Credentials deletion failures are handled
 * silently.
 *
 * @param context the calling {@link Context}.
 */
@NonNull
public Task<Void> delete(@NonNull final Context context) {
    final FirebaseUser currentUser = mAuth.getCurrentUser();
    if (currentUser == null) {
        return Tasks.forException(new FirebaseAuthInvalidUserException(String.valueOf(CommonStatusCodes.SIGN_IN_REQUIRED), "No currently signed in user."));
    }
    final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
    // Ensure the order in which tasks are executed properly destructures the user.
    return signOutIdps(context).continueWithTask(task -> {
        // Propagate exception if there was one
        task.getResult();
        if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
            Log.w(TAG, "Google Play services not available during delete");
            return Tasks.forResult((Void) null);
        }
        final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
        List<Task<?>> credentialTasks = new ArrayList<>();
        for (Credential credential : credentials) {
            credentialTasks.add(client.delete(credential));
        }
        return Tasks.whenAll(credentialTasks).continueWith(task1 -> {
            Exception e = task1.getException();
            Throwable t = e == null ? null : e.getCause();
            if (!(t instanceof ApiException) || ((ApiException) t).getStatusCode() != CommonStatusCodes.CANCELED) {
                // doesn't mean fully deleting the user failed.
                return task1.getResult();
            }
            return null;
        });
    }).continueWithTask(task -> {
        // Propagate exception if there was one
        task.getResult();
        return currentUser.delete();
    });
}
Also used : Scope(com.google.android.gms.common.api.Scope) Arrays(java.util.Arrays) Bundle(android.os.Bundle) UserInfo(com.google.firebase.auth.UserInfo) NonNull(androidx.annotation.NonNull) GoogleApiUtils(com.firebase.ui.auth.util.GoogleApiUtils) DrawableRes(androidx.annotation.DrawableRes) PhoneAuthProvider(com.google.firebase.auth.PhoneAuthProvider) GoogleAuthProvider(com.google.firebase.auth.GoogleAuthProvider) GoogleSignIn(com.google.android.gms.auth.api.signin.GoogleSignIn) RestrictTo(androidx.annotation.RestrictTo) Locale(java.util.Locale) Map(java.util.Map) GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) ProviderAvailability(com.firebase.ui.auth.util.data.ProviderAvailability) Log(android.util.Log) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) IdentityHashMap(java.util.IdentityHashMap) FirebaseAuthProvider(com.google.firebase.auth.FirebaseAuthProvider) FirebaseUser(com.google.firebase.auth.FirebaseUser) Set(java.util.Set) FacebookAuthProvider(com.google.firebase.auth.FacebookAuthProvider) CredentialRequest(com.google.android.gms.auth.api.credentials.CredentialRequest) StyleRes(androidx.annotation.StyleRes) LoginManager(com.facebook.login.LoginManager) FlowParameters(com.firebase.ui.auth.data.model.FlowParameters) Preconditions(com.firebase.ui.auth.util.Preconditions) List(java.util.List) Tasks(com.google.android.gms.tasks.Tasks) Nullable(androidx.annotation.Nullable) AuthResult(com.google.firebase.auth.AuthResult) PhoneNumberUtils(com.firebase.ui.auth.util.data.PhoneNumberUtils) ApiException(com.google.android.gms.common.api.ApiException) Context(android.content.Context) ProviderUtils(com.firebase.ui.auth.util.data.ProviderUtils) GithubAuthProvider(com.google.firebase.auth.GithubAuthProvider) Intent(android.content.Intent) ExtraConstants(com.firebase.ui.auth.util.ExtraConstants) TwitterAuthProvider(com.google.firebase.auth.TwitterAuthProvider) HashMap(java.util.HashMap) Parcel(android.os.Parcel) Task(com.google.android.gms.tasks.Task) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AuthMethodPickerActivity(com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity) CredentialUtils(com.firebase.ui.auth.util.CredentialUtils) CredentialsClient(com.google.android.gms.auth.api.credentials.CredentialsClient) StringDef(androidx.annotation.StringDef) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) Parcelable(android.os.Parcelable) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) TextUtils(android.text.TextUtils) CallSuper(androidx.annotation.CallSuper) CommonStatusCodes(com.google.android.gms.common.api.CommonStatusCodes) AuthCredential(com.google.firebase.auth.AuthCredential) Credential(com.google.android.gms.auth.api.credentials.Credential) EmailAuthProvider(com.google.firebase.auth.EmailAuthProvider) Collections(java.util.Collections) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions) FirebaseApp(com.google.firebase.FirebaseApp) RetentionPolicy(java.lang.annotation.RetentionPolicy) CredentialsClient(com.google.android.gms.auth.api.credentials.CredentialsClient) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) AuthCredential(com.google.firebase.auth.AuthCredential) Credential(com.google.android.gms.auth.api.credentials.Credential) List(java.util.List) ArrayList(java.util.ArrayList) FirebaseUser(com.google.firebase.auth.FirebaseUser) ApiException(com.google.android.gms.common.api.ApiException) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) ApiException(com.google.android.gms.common.api.ApiException) NonNull(androidx.annotation.NonNull)

Aggregations

FirebaseAuthInvalidUserException (com.google.firebase.auth.FirebaseAuthInvalidUserException)5 Intent (android.content.Intent)3 TextUtils (android.text.TextUtils)3 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 ProviderUtils (com.firebase.ui.auth.util.data.ProviderUtils)3 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)3 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)3 Activity (android.app.Activity)2 Application (android.app.Application)2 Bundle (android.os.Bundle)2 RestrictTo (androidx.annotation.RestrictTo)2 EMAIL_LINK_PROVIDER (com.firebase.ui.auth.AuthUI.EMAIL_LINK_PROVIDER)2 ErrorCodes (com.firebase.ui.auth.ErrorCodes)2 IdpResponse (com.firebase.ui.auth.IdpResponse)2 IntentRequiredException (com.firebase.ui.auth.data.model.IntentRequiredException)2 Resource (com.firebase.ui.auth.data.model.Resource)2 User (com.firebase.ui.auth.data.model.User)2 AuthMethodPickerActivity (com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity)2 RequestCodes (com.firebase.ui.auth.viewmodel.RequestCodes)2