Search in sources :

Example 1 with FirebaseAuthInvalidCredentialsException

use of com.google.firebase.auth.FirebaseAuthInvalidCredentialsException in project quickstart-android by firebase.

the class PasswordlessActivity method sendSignInLink.

/**
 * Send an email sign-in link to the specified email.
 */
private void sendSignInLink(String email) {
    ActionCodeSettings settings = ActionCodeSettings.newBuilder().setAndroidPackageName(getPackageName(), false, /* install if not available? */
    null).setHandleCodeInApp(true).setUrl("https://auth.example.com/emailSignInLink").build();
    hideKeyboard(mBinding.fieldEmail);
    showProgressBar();
    mAuth.sendSignInLinkToEmail(email, settings).addOnCompleteListener(new OnCompleteListener<Void>() {

        @Override
        public void onComplete(@NonNull Task<Void> task) {
            hideProgressBar();
            if (task.isSuccessful()) {
                Log.d(TAG, "Link sent");
                showSnackbar("Sign-in link sent!");
                mPendingEmail = email;
                mBinding.status.setText(R.string.status_email_sent);
            } else {
                Exception e = task.getException();
                Log.w(TAG, "Could not send link", e);
                showSnackbar("Failed to send link.");
                if (e instanceof FirebaseAuthInvalidCredentialsException) {
                    mBinding.fieldEmail.setError("Invalid email address.");
                }
            }
        }
    });
}
Also used : FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthActionCodeException(com.google.firebase.auth.FirebaseAuthActionCodeException)

Example 2 with FirebaseAuthInvalidCredentialsException

use of com.google.firebase.auth.FirebaseAuthInvalidCredentialsException 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 3 with FirebaseAuthInvalidCredentialsException

use of com.google.firebase.auth.FirebaseAuthInvalidCredentialsException 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 4 with FirebaseAuthInvalidCredentialsException

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

the class RegisterEmailFragment method registerUser.

private void registerUser(final String email, final String name, final String password) {
    mHelper.getFirebaseAuth().createUserWithEmailAndPassword(email, password).addOnFailureListener(new TaskFailureLogger(TAG, "Error creating user")).addOnSuccessListener(new OnSuccessListener<AuthResult>() {

        @Override
        public void onSuccess(AuthResult authResult) {
            // Set display name
            UserProfileChangeRequest changeNameRequest = new UserProfileChangeRequest.Builder().setDisplayName(name).setPhotoUri(mUser.getPhotoUri()).build();
            final FirebaseUser user = authResult.getUser();
            user.updateProfile(changeNameRequest).addOnFailureListener(new TaskFailureLogger(TAG, "Error setting display name")).addOnCompleteListener(new OnCompleteListener<Void>() {

                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    // This executes even if the name change fails, since
                    // the account creation succeeded and we want to save
                    // the credential to SmartLock (if enabled).
                    mHelper.saveCredentialsOrFinish(mSaveSmartLock, getActivity(), user, password, new IdpResponse(EmailAuthProvider.PROVIDER_ID, email));
                }
            });
        }
    }).addOnFailureListener(getActivity(), new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            mHelper.dismissDialog();
            if (e instanceof FirebaseAuthWeakPasswordException) {
                // Password too weak
                mPasswordInput.setError(getResources().getQuantityString(R.plurals.error_weak_password, R.integer.min_password_length));
            } else if (e instanceof FirebaseAuthInvalidCredentialsException) {
                // Email address is malformed
                mEmailInput.setError(getString(R.string.invalid_email_address));
            } else if (e instanceof FirebaseAuthUserCollisionException) {
                // Collision with existing user email, it should be very hard for
                // the user to even get to this error due to CheckEmailFragment.
                mEmailInput.setError(getString(R.string.error_user_collision));
            } else {
                // General error message, this branch should not be invoked but
                // covers future API changes
                mEmailInput.setError(getString(R.string.email_account_creation_error));
            }
        }
    });
}
Also used : TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) FirebaseAuthWeakPasswordException(com.google.firebase.auth.FirebaseAuthWeakPasswordException) UserProfileChangeRequest(com.google.firebase.auth.UserProfileChangeRequest) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FirebaseAuthWeakPasswordException(com.google.firebase.auth.FirebaseAuthWeakPasswordException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 5 with FirebaseAuthInvalidCredentialsException

use of com.google.firebase.auth.FirebaseAuthInvalidCredentialsException 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

FirebaseAuthInvalidCredentialsException (com.google.firebase.auth.FirebaseAuthInvalidCredentialsException)5 IdpResponse (com.firebase.ui.auth.IdpResponse)3 Intent (android.content.Intent)2 ViewModelProvider (androidx.lifecycle.ViewModelProvider)2 UserCancellationException (com.firebase.ui.auth.data.model.UserCancellationException)2 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)2 FirebaseAuthInvalidUserException (com.google.firebase.auth.FirebaseAuthInvalidUserException)2 Activity (android.app.Activity)1 Application (android.app.Application)1 Bundle (android.os.Bundle)1 TextUtils (android.text.TextUtils)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AuthUI (com.firebase.ui.auth.AuthUI)1 EMAIL_LINK_PROVIDER (com.firebase.ui.auth.AuthUI.EMAIL_LINK_PROVIDER)1 ErrorCodes (com.firebase.ui.auth.ErrorCodes)1 FirebaseAuthAnonymousUpgradeException (com.firebase.ui.auth.FirebaseAuthAnonymousUpgradeException)1 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)1 IntentRequiredException (com.firebase.ui.auth.data.model.IntentRequiredException)1