in auth/src/main/java/com/firebase/ui/auth/ui/idp/AuthMethodPickerActivity.java [271:368]
private void handleSignInOperation(final IdpConfig idpConfig, View view) {
ViewModelProvider supplier = new ViewModelProvider(this);
final String providerId = idpConfig.getProviderId();
final ProviderSignInBase<?> provider;
AuthUI authUI = getAuthUI();
switch (providerId) {
case EMAIL_LINK_PROVIDER:
case EmailAuthProvider.PROVIDER_ID:
provider = supplier.get(EmailSignInHandler.class).initWith(null);
break;
case PhoneAuthProvider.PROVIDER_ID:
provider = supplier.get(PhoneSignInHandler.class).initWith(idpConfig);
break;
case AuthUI.ANONYMOUS_PROVIDER:
provider = supplier.get(AnonymousSignInHandler.class).initWith(getFlowParams());
break;
case GoogleAuthProvider.PROVIDER_ID:
if (authUI.isUseEmulator()) {
provider = supplier.get(GenericIdpSignInHandler.class)
.initWith(GenericIdpSignInHandler.getGenericGoogleConfig());
} else {
provider = supplier.get(GoogleSignInHandler.class).initWith(
new GoogleSignInHandler.Params(idpConfig));
}
break;
case FacebookAuthProvider.PROVIDER_ID:
if (authUI.isUseEmulator()) {
provider = supplier.get(GenericIdpSignInHandler.class)
.initWith(GenericIdpSignInHandler.getGenericFacebookConfig());
} else {
provider = supplier.get(FacebookSignInHandler.class).initWith(idpConfig);
}
break;
default:
if (!TextUtils.isEmpty(
idpConfig.getParams().getString(GENERIC_OAUTH_PROVIDER_ID))) {
provider = supplier.get(GenericIdpSignInHandler.class).initWith(idpConfig);
break;
}
throw new IllegalStateException("Unknown provider: " + providerId);
}
mProviders.add(provider);
provider.getOperation().observe(this, new ResourceObserver<IdpResponse>(this) {
@Override
protected void onSuccess(@NonNull IdpResponse response) {
handleResponse(response);
}
@Override
protected void onFailure(@NonNull Exception e) {
if (e instanceof FirebaseAuthAnonymousUpgradeException) {
finish(RESULT_CANCELED, new Intent().putExtra(ExtraConstants.IDP_RESPONSE,
IdpResponse.from(e)));
return;
}
handleResponse(IdpResponse.from(e));
}
private void handleResponse(@NonNull IdpResponse response) {
// If we're using the emulator then the social flows actually use Generic IDP
// instead which means we shouldn't use the social response handler.
boolean isSocialResponse = AuthUI.SOCIAL_PROVIDERS.contains(providerId)
&& !getAuthUI().isUseEmulator();
if (!response.isSuccessful()) {
// We have no idea what provider this error stemmed from so just forward
// this along to the handler.
mHandler.startSignIn(response);
} else if (isSocialResponse) {
// Don't use the response's provider since it can be different than the one
// that launched the sign-in attempt. Ex: the email flow is started, but
// ends up turning into a Google sign-in because that account already
// existed. In the previous example, an extra sign-in would incorrectly
// started.
mHandler.startSignIn(response);
} else {
// Email, phone, or generic: the credentials should have already been saved so
// simply move along.
// Anononymous sign in also does not require any other operations.
finish(response.isSuccessful() ? RESULT_OK : RESULT_CANCELED,
response.toIntent());
}
}
});
view.setOnClickListener(view1 -> {
if (isOffline()) {
Snackbar.make(findViewById(android.R.id.content), getString(R.string.fui_no_internet), Snackbar.LENGTH_SHORT).show();
return;
}
provider.startSignIn(getAuth(), AuthMethodPickerActivity.this,
idpConfig.getProviderId());
});
}