use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class SignInKickstarter method start.
public void start() {
if (!TextUtils.isEmpty(getArguments().emailLink)) {
setResult(Resource.forFailure(new IntentRequiredException(EmailLinkCatcherActivity.createIntent(getApplication(), getArguments()), RequestCodes.EMAIL_FLOW)));
return;
}
// Signing in with Generic IDP puts the app in the background - it can be reclaimed by the
// OS during the sign in flow.
Task<AuthResult> pendingResultTask = getAuth().getPendingAuthResult();
if (pendingResultTask != null) {
pendingResultTask.addOnSuccessListener(authResult -> {
final IdpResponse response = new IdpResponse.Builder(new User.Builder(authResult.getCredential().getProvider(), authResult.getUser().getEmail()).build()).build();
handleSuccess(response, authResult);
}).addOnFailureListener(e -> setResult(Resource.forFailure(e)));
return;
}
// Only support password credentials if email auth is enabled
boolean supportPasswords = ProviderUtils.getConfigFromIdps(getArguments().providers, EmailAuthProvider.PROVIDER_ID) != null;
List<String> accountTypes = getCredentialAccountTypes();
// If the request will be empty, avoid the step entirely
boolean willRequestCredentials = supportPasswords || accountTypes.size() > 0;
if (getArguments().enableCredentials && willRequestCredentials) {
setResult(Resource.forLoading());
GoogleApiUtils.getCredentialsClient(getApplication()).request(new CredentialRequest.Builder().setPasswordLoginSupported(supportPasswords).setAccountTypes(accountTypes.toArray(new String[accountTypes.size()])).build()).addOnCompleteListener(task -> {
try {
handleCredential(task.getResult(ApiException.class).getCredential());
} catch (ResolvableApiException e) {
if (e.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
setResult(Resource.forFailure(new PendingIntentRequiredException(e.getResolution(), RequestCodes.CRED_HINT)));
} else {
startAuthMethodChoice();
}
} catch (ApiException e) {
startAuthMethodChoice();
}
});
} else {
startAuthMethodChoice();
}
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class EmailActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fui_activity_register_email);
if (savedInstanceState != null) {
return;
}
// Get email from intent (can be null)
String email = getIntent().getExtras().getString(ExtraConstants.EMAIL);
IdpResponse responseForLinking = getIntent().getExtras().getParcelable(ExtraConstants.IDP_RESPONSE);
if (email != null && responseForLinking != null) {
// got here from WelcomeBackEmailLinkPrompt
AuthUI.IdpConfig emailConfig = ProviderUtils.getConfigFromIdpsOrThrow(getFlowParams().providers, EMAIL_LINK_PROVIDER);
ActionCodeSettings actionCodeSettings = emailConfig.getParams().getParcelable(ExtraConstants.ACTION_CODE_SETTINGS);
EmailLinkPersistenceManager.getInstance().saveIdpResponseForLinking(getApplication(), responseForLinking);
boolean forceSameDevice = emailConfig.getParams().getBoolean(ExtraConstants.FORCE_SAME_DEVICE);
EmailLinkFragment fragment = EmailLinkFragment.newInstance(email, actionCodeSettings, responseForLinking, forceSameDevice);
switchFragment(fragment, R.id.fragment_register_email, EmailLinkFragment.TAG);
} else {
AuthUI.IdpConfig emailConfig = ProviderUtils.getConfigFromIdps(getFlowParams().providers, EmailAuthProvider.PROVIDER_ID);
if (emailConfig != null) {
email = emailConfig.getParams().getString(ExtraConstants.DEFAULT_EMAIL);
;
}
// Start with check email
CheckEmailFragment fragment = CheckEmailFragment.newInstance(email);
switchFragment(fragment, R.id.fragment_register_email, CheckEmailFragment.TAG);
}
}
use of com.firebase.ui.auth.IdpResponse 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.IdpResponse 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.IdpResponse in project FirebaseUI-Android by firebase.
the class AuthUiActivity method onActivityResult.
@Override
public void onActivityResult(@NonNull FirebaseAuthUIAuthenticationResult result) {
// Successfully signed in
IdpResponse response = result.getIdpResponse();
handleSignInResponse(result.getResultCode(), response);
}
Aggregations