use of com.firebase.ui.auth.util.FirebaseAuthError in project FirebaseUI-Android by firebase.
the class PhoneActivity method handleError.
private void handleError(@Nullable Exception e) {
TextInputLayout errorView = getErrorView();
if (errorView == null) {
return;
}
if (e instanceof FirebaseAuthAnonymousUpgradeException) {
IdpResponse response = ((FirebaseAuthAnonymousUpgradeException) e).getResponse();
finish(ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT, response.toIntent());
} else if (e instanceof FirebaseAuthException) {
FirebaseAuthError error = FirebaseAuthError.fromException((FirebaseAuthException) e);
if (error == FirebaseAuthError.ERROR_USER_DISABLED) {
IdpResponse response = IdpResponse.from(new FirebaseUiException(ErrorCodes.ERROR_USER_DISABLED));
finish(RESULT_CANCELED, response.toIntent());
return;
}
errorView.setError(getErrorMessage(error));
} else if (e != null) {
errorView.setError(getErrorMessage(FirebaseAuthError.ERROR_UNKNOWN));
} else {
errorView.setError(null);
}
}
use of com.firebase.ui.auth.util.FirebaseAuthError 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.firebase.ui.auth.util.FirebaseAuthError in project FirebaseUI-Android by firebase.
the class WelcomeBackPasswordPrompt method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fui_welcome_back_password_prompt_layout);
// Show keyboard
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
mIdpResponse = IdpResponse.fromResultIntent(getIntent());
String email = mIdpResponse.getEmail();
mDoneButton = findViewById(R.id.button_done);
mProgressBar = findViewById(R.id.top_progress_bar);
mPasswordLayout = findViewById(R.id.password_layout);
mPasswordField = findViewById(R.id.password);
ImeHelper.setImeOnDoneListener(mPasswordField, this);
// Create welcome back text with email bolded.
String bodyText = getString(R.string.fui_welcome_back_password_prompt_body, email);
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(bodyText);
TextHelper.boldAllOccurencesOfText(spannableStringBuilder, bodyText, email);
TextView bodyTextView = findViewById(R.id.welcome_back_password_body);
bodyTextView.setText(spannableStringBuilder);
// Click listeners
mDoneButton.setOnClickListener(this);
findViewById(R.id.trouble_signing_in).setOnClickListener(this);
// Initialize ViewModel with arguments
mHandler = new ViewModelProvider(this).get(WelcomeBackPasswordHandler.class);
mHandler.init(getFlowParams());
// Observe the state of the main auth operation
mHandler.getOperation().observe(this, new ResourceObserver<IdpResponse>(this, R.string.fui_progress_dialog_signing_in) {
@Override
protected void onSuccess(@NonNull IdpResponse response) {
startSaveCredentials(mHandler.getCurrentUser(), response, mHandler.getPendingPassword());
}
@Override
protected void onFailure(@NonNull Exception e) {
if (e instanceof FirebaseAuthAnonymousUpgradeException) {
IdpResponse response = ((FirebaseAuthAnonymousUpgradeException) e).getResponse();
finish(ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT, response.toIntent());
return;
}
if (e instanceof FirebaseAuthException) {
FirebaseAuthException authEx = (FirebaseAuthException) e;
FirebaseAuthError error = FirebaseAuthError.fromException(authEx);
if (error == FirebaseAuthError.ERROR_USER_DISABLED) {
IdpResponse resp = IdpResponse.from(new FirebaseUiException(ErrorCodes.ERROR_USER_DISABLED));
finish(RESULT_CANCELED, resp.toIntent());
return;
}
}
mPasswordLayout.setError(getString(getErrorMessage(e)));
}
});
TextView footerText = findViewById(R.id.email_footer_tos_and_pp_text);
PrivacyDisclosureUtils.setupTermsOfServiceFooter(this, getFlowParams(), footerText);
}
use of com.firebase.ui.auth.util.FirebaseAuthError in project FirebaseUI-Android by firebase.
the class GenericIdpSignInHandler method handleNormalSignInFlow.
protected void handleNormalSignInFlow(final FirebaseAuth auth, final HelperActivityBase activity, final OAuthProvider provider) {
final boolean useEmulator = activity.getAuthUI().isUseEmulator();
auth.startActivityForSignInWithProvider(activity, provider).addOnSuccessListener(authResult -> handleSuccess(useEmulator, provider.getProviderId(), authResult.getUser(), (OAuthCredential) authResult.getCredential(), authResult.getAdditionalUserInfo().isNewUser())).addOnFailureListener(e -> {
if (e instanceof FirebaseAuthException) {
FirebaseAuthError error = FirebaseAuthError.fromException((FirebaseAuthException) e);
if (e instanceof FirebaseAuthUserCollisionException) {
FirebaseAuthUserCollisionException collisionException = (FirebaseAuthUserCollisionException) e;
setResult(Resource.forFailure(new FirebaseUiUserCollisionException(ErrorCodes.ERROR_GENERIC_IDP_RECOVERABLE_ERROR, "Recoverable error.", provider.getProviderId(), collisionException.getEmail(), collisionException.getUpdatedCredential())));
} else if (error == FirebaseAuthError.ERROR_WEB_CONTEXT_CANCELED) {
setResult(Resource.forFailure(new UserCancellationException()));
} else {
setResult(Resource.forFailure(e));
}
} else {
setResult(Resource.forFailure(e));
}
});
}
Aggregations