use of com.firebase.ui.auth.ui.HelperActivityBase in project FirebaseUI-Android by firebase.
the class GenericIdpSignInHandler method handleAnonymousUpgradeFlow.
private void handleAnonymousUpgradeFlow(final FirebaseAuth auth, final HelperActivityBase activity, final OAuthProvider provider, final FlowParameters flowParameters) {
final boolean useEmulator = activity.getAuthUI().isUseEmulator();
auth.getCurrentUser().startActivityForLinkWithProvider(activity, provider).addOnSuccessListener(authResult -> handleSuccess(useEmulator, provider.getProviderId(), authResult.getUser(), (OAuthCredential) authResult.getCredential(), authResult.getAdditionalUserInfo().isNewUser())).addOnFailureListener(e -> {
if (!(e instanceof FirebaseAuthUserCollisionException)) {
setResult(Resource.forFailure(e));
return;
}
FirebaseAuthUserCollisionException collisionException = (FirebaseAuthUserCollisionException) e;
final AuthCredential credential = collisionException.getUpdatedCredential();
final String email = collisionException.getEmail();
// Case 1: Anonymous user trying to link with an existing user
// Case 2: Anonymous user trying to link with a provider keyed
// by an email that already belongs to an existing account
// (linking flow)
ProviderUtils.fetchSortedProviders(auth, flowParameters, email).addOnSuccessListener(providers -> {
if (providers.isEmpty()) {
String errorMessage = "Unable to complete the linkingflow -" + " the user is using " + "unsupported providers.";
setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.DEVELOPER_ERROR, errorMessage)));
return;
}
if (providers.contains(provider.getProviderId())) {
// Case 1
handleMergeFailure(credential);
} else {
// Case 2 - linking flow to be handled by
// SocialProviderResponseHandler
setResult(Resource.forFailure(new FirebaseUiUserCollisionException(ErrorCodes.ERROR_GENERIC_IDP_RECOVERABLE_ERROR, "Recoverable error.", provider.getProviderId(), email, credential)));
}
});
});
}
use of com.firebase.ui.auth.ui.HelperActivityBase in project FirebaseUI-Android by firebase.
the class TestHelper method getHelperActivity.
public static HelperActivityBase getHelperActivity(FlowParameters parameters) {
AuthUI authUI = AuthUI.getInstance(parameters.appName);
HelperActivityBase activity = mock(HelperActivityBase.class);
when(activity.getFlowParams()).thenReturn(parameters);
when(activity.getAuthUI()).thenReturn(authUI);
when(activity.getAuth()).thenReturn(authUI.getAuth());
return activity;
}
use of com.firebase.ui.auth.ui.HelperActivityBase 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