Search in sources :

Example 1 with IntentRequiredException

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)));
    }
}
Also used : IntentRequiredException(com.firebase.ui.auth.data.model.IntentRequiredException) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException) User(com.firebase.ui.auth.data.model.User) Bundle(android.os.Bundle)

Example 2 with IntentRequiredException

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;
}
Also used : IntentRequiredException(com.firebase.ui.auth.data.model.IntentRequiredException) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException)

Example 3 with IntentRequiredException

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;
}
Also used : IntentRequiredException(com.firebase.ui.auth.data.model.IntentRequiredException) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException)

Example 4 with IntentRequiredException

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();
    }
}
Also used : ProviderUtils(com.firebase.ui.auth.util.data.ProviderUtils) Bundle(android.os.Bundle) EmailLinkCatcherActivity(com.firebase.ui.auth.ui.email.EmailLinkCatcherActivity) EMAIL_LINK_PROVIDER(com.firebase.ui.auth.AuthUI.EMAIL_LINK_PROVIDER) PhoneActivity(com.firebase.ui.auth.ui.phone.PhoneActivity) NonNull(androidx.annotation.NonNull) User(com.firebase.ui.auth.data.model.User) IntentRequiredException(com.firebase.ui.auth.data.model.IntentRequiredException) Intent(android.content.Intent) Resource(com.firebase.ui.auth.data.model.Resource) ExtraConstants(com.firebase.ui.auth.util.ExtraConstants) GoogleApiUtils(com.firebase.ui.auth.util.GoogleApiUtils) PhoneAuthProvider(com.google.firebase.auth.PhoneAuthProvider) Task(com.google.android.gms.tasks.Task) ArrayList(java.util.ArrayList) GoogleAuthProvider(com.google.firebase.auth.GoogleAuthProvider) AuthMethodPickerActivity(com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity) SingleSignInActivity(com.firebase.ui.auth.ui.idp.SingleSignInActivity) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) AuthUI(com.firebase.ui.auth.AuthUI) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) EmailActivity(com.firebase.ui.auth.ui.email.EmailActivity) UserCancellationException(com.firebase.ui.auth.data.model.UserCancellationException) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) SignInViewModelBase(com.firebase.ui.auth.viewmodel.SignInViewModelBase) TextUtils(android.text.TextUtils) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) CredentialRequestResponse(com.google.android.gms.auth.api.credentials.CredentialRequestResponse) CredentialRequest(com.google.android.gms.auth.api.credentials.CredentialRequest) CommonStatusCodes(com.google.android.gms.common.api.CommonStatusCodes) List(java.util.List) Credential(com.google.android.gms.auth.api.credentials.Credential) Nullable(androidx.annotation.Nullable) EmailAuthProvider(com.google.firebase.auth.EmailAuthProvider) Application(android.app.Application) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) RequestCodes(com.firebase.ui.auth.viewmodel.RequestCodes) AuthResult(com.google.firebase.auth.AuthResult) ErrorCodes(com.firebase.ui.auth.ErrorCodes) Activity(android.app.Activity) ApiException(com.google.android.gms.common.api.ApiException) IdpResponse(com.firebase.ui.auth.IdpResponse) CredentialRequest(com.google.android.gms.auth.api.credentials.CredentialRequest) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) AuthResult(com.google.firebase.auth.AuthResult) IntentRequiredException(com.firebase.ui.auth.data.model.IntentRequiredException) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException) IdpResponse(com.firebase.ui.auth.IdpResponse) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) ApiException(com.google.android.gms.common.api.ApiException)

Example 5 with IntentRequiredException

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()));
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) FakeSignInMethodQueryResult(com.firebase.ui.auth.testhelpers.FakeSignInMethodQueryResult) IntentRequiredException(com.firebase.ui.auth.data.model.IntentRequiredException) InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Aggregations

IntentRequiredException (com.firebase.ui.auth.data.model.IntentRequiredException)7 IdpResponse (com.firebase.ui.auth.IdpResponse)4 PendingIntentRequiredException (com.firebase.ui.auth.data.model.PendingIntentRequiredException)4 Resource (com.firebase.ui.auth.data.model.Resource)4 User (com.firebase.ui.auth.data.model.User)3 FakeSignInMethodQueryResult (com.firebase.ui.auth.testhelpers.FakeSignInMethodQueryResult)3 AuthCredential (com.google.firebase.auth.AuthCredential)3 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)3 Test (org.junit.Test)3 InOrder (org.mockito.InOrder)3 Bundle (android.os.Bundle)2 Activity (android.app.Activity)1 Application (android.app.Application)1 Intent (android.content.Intent)1 TextUtils (android.text.TextUtils)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AuthUI (com.firebase.ui.auth.AuthUI)1 EMAIL_LINK_PROVIDER (com.firebase.ui.auth.AuthUI.EMAIL_LINK_PROVIDER)1 ErrorCodes (com.firebase.ui.auth.ErrorCodes)1