use of com.firebase.ui.auth.FirebaseUiException in project FirebaseUI-Android by firebase.
the class SmartLockHandler method onActivityResult.
/**
* Forward the result of a resolution from the Activity to the ViewModel.
*/
public void onActivityResult(int requestCode, int resultCode) {
if (requestCode == RequestCodes.CRED_SAVE) {
if (resultCode == Activity.RESULT_OK) {
setResult(Resource.forSuccess(mResponse));
} else {
Log.e(TAG, "SAVE: Canceled by user.");
FirebaseUiException exception = new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR, "Save canceled by user.");
setResult(Resource.forFailure(exception));
}
}
}
use of com.firebase.ui.auth.FirebaseUiException in project FirebaseUI-Android by firebase.
the class CheckEmailFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mHandler = new ViewModelProvider(this).get(CheckEmailHandler.class);
mHandler.init(getFlowParams());
FragmentActivity activity = getActivity();
if (!(activity instanceof CheckEmailListener)) {
throw new IllegalStateException("Activity must implement CheckEmailListener");
}
mListener = (CheckEmailListener) activity;
mHandler.getOperation().observe(getViewLifecycleOwner(), new ResourceObserver<User>(this, R.string.fui_progress_dialog_checking_accounts) {
@Override
protected void onSuccess(@NonNull User user) {
String email = user.getEmail();
String provider = user.getProviderId();
mEmailEditText.setText(email);
// noinspection ConstantConditions new user
if (provider == null) {
mListener.onNewUser(new User.Builder(EmailAuthProvider.PROVIDER_ID, email).setName(user.getName()).setPhotoUri(user.getPhotoUri()).build());
} else if (provider.equals(EmailAuthProvider.PROVIDER_ID) || provider.equals(EMAIL_LINK_PROVIDER)) {
mListener.onExistingEmailUser(user);
} else {
mListener.onExistingIdpUser(user);
}
}
@Override
protected void onFailure(@NonNull Exception e) {
if (e instanceof FirebaseUiException && ((FirebaseUiException) e).getErrorCode() == ErrorCodes.DEVELOPER_ERROR) {
mListener.onDeveloperFailure(e);
}
if (e instanceof FirebaseNetworkException) {
Snackbar.make(getView(), getString(R.string.fui_no_internet), Snackbar.LENGTH_SHORT).show();
}
// Otherwise just let the user enter their data
}
});
if (savedInstanceState != null) {
return;
}
// Check for email
String email = getArguments().getString(ExtraConstants.EMAIL);
if (!TextUtils.isEmpty(email)) {
mEmailEditText.setText(email);
validateAndProceed();
} else if (getFlowParams().enableHints) {
mHandler.fetchCredential();
}
}
use of com.firebase.ui.auth.FirebaseUiException 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.FirebaseUiException 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.FirebaseUiException in project FirebaseUI-Android by firebase.
the class WelcomeBackIdpPrompt method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fui_welcome_back_idp_prompt_layout);
mDoneButton = findViewById(R.id.welcome_back_idp_button);
mProgressBar = findViewById(R.id.top_progress_bar);
mPromptText = findViewById(R.id.welcome_back_idp_prompt);
User existingUser = User.getUser(getIntent());
IdpResponse requestedUserResponse = IdpResponse.fromResultIntent(getIntent());
ViewModelProvider supplier = new ViewModelProvider(this);
final LinkingSocialProviderResponseHandler handler = supplier.get(LinkingSocialProviderResponseHandler.class);
handler.init(getFlowParams());
if (requestedUserResponse != null) {
handler.setRequestedSignInCredentialForEmail(ProviderUtils.getAuthCredential(requestedUserResponse), existingUser.getEmail());
}
final String providerId = existingUser.getProviderId();
AuthUI.IdpConfig config = ProviderUtils.getConfigFromIdps(getFlowParams().providers, providerId);
if (config == null) {
finish(RESULT_CANCELED, IdpResponse.getErrorIntent(new FirebaseUiException(ErrorCodes.DEVELOPER_ERROR, "Firebase login unsuccessful." + " Account linking failed due to provider not enabled by application: " + providerId)));
return;
}
String providerName;
String genericOAuthProviderId = config.getParams().getString(ExtraConstants.GENERIC_OAUTH_PROVIDER_ID);
boolean useEmulator = getAuthUI().isUseEmulator();
switch(providerId) {
case GoogleAuthProvider.PROVIDER_ID:
if (useEmulator) {
mProvider = supplier.get(GenericIdpAnonymousUpgradeLinkingHandler.class).initWith(GenericIdpSignInHandler.getGenericGoogleConfig());
} else {
mProvider = supplier.get(GoogleSignInHandler.class).initWith(new GoogleSignInHandler.Params(config, existingUser.getEmail()));
}
providerName = getString(R.string.fui_idp_name_google);
break;
case FacebookAuthProvider.PROVIDER_ID:
if (useEmulator) {
mProvider = supplier.get(GenericIdpAnonymousUpgradeLinkingHandler.class).initWith(GenericIdpSignInHandler.getGenericFacebookConfig());
} else {
mProvider = supplier.get(FacebookSignInHandler.class).initWith(config);
}
providerName = getString(R.string.fui_idp_name_facebook);
break;
default:
if (TextUtils.equals(providerId, genericOAuthProviderId)) {
mProvider = supplier.get(GenericIdpAnonymousUpgradeLinkingHandler.class).initWith(config);
providerName = config.getParams().getString(ExtraConstants.GENERIC_OAUTH_PROVIDER_NAME);
} else {
throw new IllegalStateException("Invalid provider id: " + providerId);
}
}
mProvider.getOperation().observe(this, new ResourceObserver<IdpResponse>(this) {
@Override
protected void onSuccess(@NonNull IdpResponse response) {
boolean isGenericIdp = getAuthUI().isUseEmulator() || !AuthUI.SOCIAL_PROVIDERS.contains(response.getProviderType());
if (isGenericIdp && !response.hasCredentialForLinking() && !handler.hasCredentialForLinking()) {
// Generic Idp does not return a credential - if this is not a linking flow,
// the user is already signed in and we are done.
finish(RESULT_OK, response.toIntent());
return;
}
handler.startSignIn(response);
}
@Override
protected void onFailure(@NonNull Exception e) {
handler.startSignIn(IdpResponse.from(e));
}
});
mPromptText.setText(getString(R.string.fui_welcome_back_idp_prompt, existingUser.getEmail(), providerName));
mDoneButton.setOnClickListener(view -> mProvider.startSignIn(getAuth(), WelcomeBackIdpPrompt.this, providerId));
handler.getOperation().observe(this, new ResourceObserver<IdpResponse>(this) {
@Override
protected void onSuccess(@NonNull IdpResponse response) {
finish(RESULT_OK, response.toIntent());
}
@Override
protected void onFailure(@NonNull Exception e) {
if (e instanceof FirebaseAuthAnonymousUpgradeException) {
IdpResponse response = ((FirebaseAuthAnonymousUpgradeException) e).getResponse();
finish(ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT, response.toIntent());
} else {
finish(RESULT_CANCELED, IdpResponse.getErrorIntent(e));
}
}
});
TextView footerText = findViewById(R.id.email_footer_tos_and_pp_text);
PrivacyDisclosureUtils.setupTermsOfServiceFooter(this, getFlowParams(), footerText);
}
Aggregations