use of com.firebase.ui.auth.IdpResponse 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);
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class EmailLinkFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initHandler();
String email = getArguments().getString(ExtraConstants.EMAIL);
ActionCodeSettings actionCodeSettings = getArguments().getParcelable(ExtraConstants.ACTION_CODE_SETTINGS);
IdpResponse idpResponseForLinking = getArguments().getParcelable(ExtraConstants.IDP_RESPONSE);
boolean forceSameDevice = getArguments().getBoolean(ExtraConstants.FORCE_SAME_DEVICE);
if (!mEmailSent) {
mEmailLinkSendEmailHandler.sendSignInLinkToEmail(email, actionCodeSettings, idpResponseForLinking, forceSameDevice);
}
}
use of com.firebase.ui.auth.IdpResponse 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.IdpResponse in project FirebaseUI-Android by firebase.
the class GenericIdpSignInHandler method handleMergeFailure.
protected void handleMergeFailure(@NonNull AuthCredential credential) {
IdpResponse failureResponse = new IdpResponse.Builder().setPendingCredential(credential).build();
setResult(Resource.forFailure(new FirebaseAuthAnonymousUpgradeException(ErrorCodes.ANONYMOUS_UPGRADE_MERGE_CONFLICT, failureResponse)));
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class SignedInActivity method onCreate.
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
if (currentUser == null) {
startActivity(AuthUiActivity.createIntent(this));
finish();
return;
}
IdpResponse response = getIntent().getParcelableExtra(ExtraConstants.IDP_RESPONSE);
mBinding = SignedInLayoutBinding.inflate(getLayoutInflater());
setContentView(mBinding.getRoot());
populateProfile(response);
populateIdpToken(response);
mBinding.deleteAccount.setOnClickListener(view -> deleteAccountClicked());
mBinding.signOut.setOnClickListener(view -> signOut());
}
Aggregations