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.");
}
}
}
});
}
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);
}
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();
});
}
}
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));
}
}
});
}
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));
}
}
});
}
Aggregations