Search in sources :

Example 1 with PendingIntentRequiredException

use of com.firebase.ui.auth.data.model.PendingIntentRequiredException in project FirebaseUI-Android by firebase.

the class SmartLockHandlerTest method testSaveCredentials_resolution.

@Test
public void testSaveCredentials_resolution() {
    mHandler.getOperation().observeForever(mResultObserver);
    // Mock credentials to throw an RAE
    ResolvableApiException mockRae = mock(ResolvableApiException.class);
    when(mMockCredentials.save(any(Credential.class))).thenReturn(AutoCompleteTask.forFailure(mockRae));
    // Kick off save
    mHandler.saveCredentials(TestHelper.getMockFirebaseUser(), TestConstants.PASSWORD, null);
    InOrder inOrder = inOrder(mResultObserver);
    inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    // Make sure we get a resolution
    ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class);
    inOrder.verify(mResultObserver).onChanged(resolveCaptor.capture());
    // Call activity result
    PendingIntentRequiredException e = ((PendingIntentRequiredException) resolveCaptor.getValue().getException());
    mHandler.onActivityResult(e.getRequestCode(), Activity.RESULT_OK);
    // Make sure we get success
    inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
Also used : ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) Credential(com.google.android.gms.auth.api.credentials.Credential) InOrder(org.mockito.InOrder) Resource(com.firebase.ui.auth.data.model.Resource) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException) Test(org.junit.Test)

Example 2 with PendingIntentRequiredException

use of com.firebase.ui.auth.data.model.PendingIntentRequiredException in project FirebaseUI-Android by firebase.

the class SmartLockHandler method saveCredentials.

/**
 * Initialize saving a credential.
 */
public void saveCredentials(@Nullable Credential credential) {
    if (!getArguments().enableCredentials) {
        setResult(Resource.forSuccess(mResponse));
        return;
    }
    setResult(Resource.forLoading());
    if (credential == null) {
        setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR, "Failed to build credential.")));
        return;
    }
    deleteUnusedCredentials();
    getCredentialsClient().save(credential).addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            setResult(Resource.forSuccess(mResponse));
        } else if (task.getException() instanceof ResolvableApiException) {
            ResolvableApiException rae = (ResolvableApiException) task.getException();
            setResult(Resource.forFailure(new PendingIntentRequiredException(rae.getResolution(), RequestCodes.CRED_SAVE)));
        } else {
            Log.w(TAG, "Non-resolvable exception: " + task.getException());
            setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR, "Error when saving credential.", task.getException())));
        }
    });
}
Also used : ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) FirebaseUiException(com.firebase.ui.auth.FirebaseUiException) PendingIntentRequiredException(com.firebase.ui.auth.data.model.PendingIntentRequiredException)

Example 3 with PendingIntentRequiredException

use of com.firebase.ui.auth.data.model.PendingIntentRequiredException 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 4 with PendingIntentRequiredException

use of com.firebase.ui.auth.data.model.PendingIntentRequiredException 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 5 with PendingIntentRequiredException

use of com.firebase.ui.auth.data.model.PendingIntentRequiredException 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)

Aggregations

PendingIntentRequiredException (com.firebase.ui.auth.data.model.PendingIntentRequiredException)5 IntentRequiredException (com.firebase.ui.auth.data.model.IntentRequiredException)3 ResolvableApiException (com.google.android.gms.common.api.ResolvableApiException)3 Resource (com.firebase.ui.auth.data.model.Resource)2 Credential (com.google.android.gms.auth.api.credentials.Credential)2 Activity (android.app.Activity)1 Application (android.app.Application)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)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 FirebaseUiException (com.firebase.ui.auth.FirebaseUiException)1 IdpResponse (com.firebase.ui.auth.IdpResponse)1 User (com.firebase.ui.auth.data.model.User)1 UserCancellationException (com.firebase.ui.auth.data.model.UserCancellationException)1 EmailActivity (com.firebase.ui.auth.ui.email.EmailActivity)1