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