use of com.firebase.ui.auth.data.model.UserCancellationException in project FirebaseUI-Android by firebase.
the class AuthMethodPickerActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FlowParameters params = getFlowParams();
customLayout = params.authMethodPickerLayout;
mHandler = new ViewModelProvider(this).get(SocialProviderResponseHandler.class);
mHandler.init(params);
mProviders = new ArrayList<>();
if (customLayout != null) {
setContentView(customLayout.getMainLayout());
// Setup using custom layout
populateIdpListCustomLayout(params.providers);
} else {
setContentView(R.layout.fui_auth_method_picker_layout);
// UI only with default layout
mProgressBar = findViewById(R.id.top_progress_bar);
mProviderHolder = findViewById(R.id.btn_holder);
populateIdpList(params.providers);
int logoId = params.logoId;
if (logoId == AuthUI.NO_LOGO) {
findViewById(R.id.logo).setVisibility(View.GONE);
ConstraintLayout layout = findViewById(R.id.root);
ConstraintSet constraints = new ConstraintSet();
constraints.clone(layout);
constraints.setHorizontalBias(R.id.container, 0.5f);
constraints.setVerticalBias(R.id.container, 0.5f);
constraints.applyTo(layout);
} else {
ImageView logo = findViewById(R.id.logo);
logo.setImageResource(logoId);
}
}
boolean tosAndPpConfigured = getFlowParams().isPrivacyPolicyUrlProvided() && getFlowParams().isTermsOfServiceUrlProvided();
int termsTextId = customLayout == null ? R.id.main_tos_and_pp : customLayout.getTosPpView();
if (termsTextId >= 0) {
TextView termsText = findViewById(termsTextId);
// No ToS or PP provided, so we should hide the view entirely
if (!tosAndPpConfigured) {
termsText.setVisibility(View.GONE);
} else {
PrivacyDisclosureUtils.setupTermsOfServiceAndPrivacyPolicyText(this, getFlowParams(), termsText);
}
}
// Handler for both
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, null);
}
@Override
protected void onFailure(@NonNull Exception e) {
if (e instanceof UserCancellationException) {
// User pressed back, there is no error.
return;
}
if (e instanceof FirebaseAuthAnonymousUpgradeException) {
finish(ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT, ((FirebaseAuthAnonymousUpgradeException) e).getResponse().toIntent());
} else if (e instanceof FirebaseUiException) {
FirebaseUiException fue = (FirebaseUiException) e;
finish(RESULT_CANCELED, IdpResponse.from(fue).toIntent());
} else {
String text = getString(R.string.fui_error_unknown);
Toast.makeText(AuthMethodPickerActivity.this, text, Toast.LENGTH_SHORT).show();
}
}
});
}
use of com.firebase.ui.auth.data.model.UserCancellationException in project FirebaseUI-Android by firebase.
the class GoogleSignInHandler method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode != RequestCodes.GOOGLE_PROVIDER) {
return;
}
try {
GoogleSignInAccount account = GoogleSignIn.getSignedInAccountFromIntent(data).getResult(ApiException.class);
setResult(Resource.forSuccess(createIdpResponse(account)));
} catch (ApiException e) {
if (e.getStatusCode() == CommonStatusCodes.INVALID_ACCOUNT) {
// If we get INVALID_ACCOUNT, it means the pre-set account was not available on the
// device so set the email to null and launch the sign-in picker.
mEmail = null;
start();
} else if (e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CURRENTLY_IN_PROGRESS) {
// Hack for https://github.com/googlesamples/google-services/issues/345
// Google remembers the account so the picker doesn't appear twice for the user.
start();
} else if (e.getStatusCode() == GoogleSignInStatusCodes.SIGN_IN_CANCELLED) {
setResult(Resource.forFailure(new UserCancellationException()));
} else {
if (e.getStatusCode() == CommonStatusCodes.DEVELOPER_ERROR) {
Log.w(TAG, "Developer error: this application is misconfigured. " + "Check your SHA1 and package name in the Firebase console.");
}
setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.PROVIDER_ERROR, "Code: " + e.getStatusCode() + ", message: " + e.getMessage())));
}
}
}
use of com.firebase.ui.auth.data.model.UserCancellationException 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));
}
}
});
}
use of com.firebase.ui.auth.data.model.UserCancellationException 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