use of com.firebase.ui.auth.data.model.IntentRequiredException in project FirebaseUI-Android by firebase.
the class SignInKickstarter method redirectSignIn.
private void redirectSignIn(String provider, String id) {
switch(provider) {
case EmailAuthProvider.PROVIDER_ID:
setResult(Resource.forFailure(new IntentRequiredException(EmailActivity.createIntent(getApplication(), getArguments(), id), RequestCodes.EMAIL_FLOW)));
break;
case PhoneAuthProvider.PROVIDER_ID:
Bundle args = new Bundle();
args.putString(ExtraConstants.PHONE, id);
setResult(Resource.forFailure(new IntentRequiredException(PhoneActivity.createIntent(getApplication(), getArguments(), args), RequestCodes.PHONE_FLOW)));
break;
default:
setResult(Resource.forFailure(new IntentRequiredException(SingleSignInActivity.createIntent(getApplication(), getArguments(), new User.Builder(provider, id).build()), RequestCodes.PROVIDER_FLOW)));
}
}
use of com.firebase.ui.auth.data.model.IntentRequiredException in project FirebaseUI-Android by firebase.
the class FlowUtils method unhandled.
public static boolean unhandled(@NonNull FragmentBase fragment, @Nullable Exception e) {
if (e instanceof IntentRequiredException) {
IntentRequiredException typed = (IntentRequiredException) e;
fragment.startActivityForResult(typed.getIntent(), typed.getRequestCode());
return false;
} else if (e instanceof PendingIntentRequiredException) {
PendingIntentRequiredException typed = (PendingIntentRequiredException) e;
startIntentSenderForResult(fragment, typed.getPendingIntent(), typed.getRequestCode());
return false;
}
return true;
}
use of com.firebase.ui.auth.data.model.IntentRequiredException in project FirebaseUI-Android by firebase.
the class FlowUtils method unhandled.
public static boolean unhandled(@NonNull HelperActivityBase activity, @Nullable Exception e) {
if (e instanceof IntentRequiredException) {
IntentRequiredException typed = (IntentRequiredException) e;
activity.startActivityForResult(typed.getIntent(), typed.getRequestCode());
return false;
} else if (e instanceof PendingIntentRequiredException) {
PendingIntentRequiredException typed = (PendingIntentRequiredException) e;
startIntentSenderForResult(activity, typed.getPendingIntent(), typed.getRequestCode());
return false;
}
return true;
}
use of com.firebase.ui.auth.data.model.IntentRequiredException 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.data.model.IntentRequiredException in project FirebaseUI-Android by firebase.
the class SocialProviderResponseHandlerTest method testSignInIdp_resolution.
@Test
public void testSignInIdp_resolution() {
mHandler.getOperation().observeForever(mResultObserver);
when(mMockAuth.signInWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forFailure(new FirebaseAuthUserCollisionException("foo", "bar")));
when(mMockAuth.fetchSignInMethodsForEmail(any(String.class))).thenReturn(AutoCompleteTask.forSuccess(new FakeSignInMethodQueryResult(Collections.singletonList(FacebookAuthProvider.FACEBOOK_SIGN_IN_METHOD))));
IdpResponse response = new IdpResponse.Builder(new User.Builder(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).setToken(TestConstants.TOKEN).build();
mHandler.startSignIn(response);
verify(mMockAuth).signInWithCredential(any(AuthCredential.class));
verify(mMockAuth).fetchSignInMethodsForEmail(any(String.class));
InOrder inOrder = inOrder(mResultObserver);
inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isLoading()));
ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class);
inOrder.verify(mResultObserver).onChanged(resolveCaptor.capture());
// Call activity result
IntentRequiredException e = ((IntentRequiredException) resolveCaptor.getValue().getException());
mHandler.onActivityResult(e.getRequestCode(), Activity.RESULT_OK, response.toIntent());
// Make sure we get success
inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
Aggregations