Search in sources :

Example 1 with ActionCodeSettings

use of com.google.firebase.auth.ActionCodeSettings in project quickstart-android by firebase.

the class PasswordlessActivity method sendSignInLink.

/**
 * Send an email sign-in link to the specified email.
 */
private void sendSignInLink(String email) {
    ActionCodeSettings settings = ActionCodeSettings.newBuilder().setAndroidPackageName(getPackageName(), false, /* install if not available? */
    null).setHandleCodeInApp(true).setUrl("https://auth.example.com/emailSignInLink").build();
    hideKeyboard(mBinding.fieldEmail);
    showProgressBar();
    mAuth.sendSignInLinkToEmail(email, settings).addOnCompleteListener(new OnCompleteListener<Void>() {

        @Override
        public void onComplete(@NonNull Task<Void> task) {
            hideProgressBar();
            if (task.isSuccessful()) {
                Log.d(TAG, "Link sent");
                showSnackbar("Sign-in link sent!");
                mPendingEmail = email;
                mBinding.status.setText(R.string.status_email_sent);
            } else {
                Exception e = task.getException();
                Log.w(TAG, "Could not send link", e);
                showSnackbar("Failed to send link.");
                if (e instanceof FirebaseAuthInvalidCredentialsException) {
                    mBinding.fieldEmail.setError("Invalid email address.");
                }
            }
        }
    });
}
Also used : FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) FirebaseAuthInvalidCredentialsException(com.google.firebase.auth.FirebaseAuthInvalidCredentialsException) FirebaseAuthActionCodeException(com.google.firebase.auth.FirebaseAuthActionCodeException)

Example 2 with ActionCodeSettings

use of com.google.firebase.auth.ActionCodeSettings in project FirebaseUI-Android by firebase.

the class EmailLinkSendEmailHandlerTest method testSendSignInLinkToEmail_normalFlow_expectFailure.

@Test
@SuppressWarnings("unchecked")
public void testSendSignInLinkToEmail_normalFlow_expectFailure() {
    mHandler.getOperation().observeForever(mResponseObserver);
    boolean forceSameDevice = true;
    ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder().setUrl(URL).build();
    when(mMockAuth.sendSignInLinkToEmail(any(String.class), any(ActionCodeSettings.class))).thenReturn(AutoCompleteTask.forFailure(new Exception()));
    mHandler.sendSignInLinkToEmail(TestConstants.EMAIL, actionCodeSettings, null, forceSameDevice);
    ArgumentCaptor<ActionCodeSettings> acsCaptor = ArgumentCaptor.forClass(ActionCodeSettings.class);
    verify(mMockAuth).sendSignInLinkToEmail(eq(TestConstants.EMAIL), acsCaptor.capture());
    assertThat(acsCaptor.getValue()).isNotEqualTo(actionCodeSettings);
    validateSessionIdAddedToContinueUrl(acsCaptor.getValue(), null, forceSameDevice);
    ArgumentCaptor<Resource<String>> captor = ArgumentCaptor.forClass(Resource.class);
    InOrder inOrder = inOrder(mResponseObserver);
    inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    inOrder.verify(mResponseObserver).onChanged(captor.capture());
    assertThat(captor.getValue().getState()).isEqualTo(State.FAILURE);
    assertThat(captor.getValue().getException()).isNotNull();
}
Also used : InOrder(org.mockito.InOrder) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) Resource(com.firebase.ui.auth.data.model.Resource) Test(org.junit.Test)

Example 3 with ActionCodeSettings

use of com.google.firebase.auth.ActionCodeSettings in project FirebaseUI-Android by firebase.

the class EmailLinkSendEmailHandlerTest method testSendSignInLinkToEmail_normalFlow_expectSuccess.

@Test
@SuppressWarnings("unchecked")
public void testSendSignInLinkToEmail_normalFlow_expectSuccess() {
    mHandler.getOperation().observeForever(mResponseObserver);
    boolean forceSameDevice = false;
    ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder().setUrl(URL).build();
    when(mMockAuth.sendSignInLinkToEmail(any(String.class), any(ActionCodeSettings.class))).thenReturn(AutoCompleteTask.forSuccess(null));
    mHandler.sendSignInLinkToEmail(TestConstants.EMAIL, actionCodeSettings, null, forceSameDevice);
    ArgumentCaptor<ActionCodeSettings> acsCaptor = ArgumentCaptor.forClass(ActionCodeSettings.class);
    verify(mMockAuth).sendSignInLinkToEmail(eq(TestConstants.EMAIL), acsCaptor.capture());
    assertThat(acsCaptor.getValue()).isNotEqualTo(actionCodeSettings);
    validateSessionIdAddedToContinueUrl(acsCaptor.getValue(), null, forceSameDevice);
    String email = mPersistenceManager.retrieveSessionRecord(ApplicationProvider.getApplicationContext()).getEmail();
    assertThat(email).isNotNull();
    assertThat(email).isEqualTo(TestConstants.EMAIL);
    ArgumentCaptor<Resource<String>> captor = ArgumentCaptor.forClass(Resource.class);
    InOrder inOrder = inOrder(mResponseObserver);
    inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
    inOrder.verify(mResponseObserver).onChanged(captor.capture());
    assertThat(captor.getValue().getState()).isEqualTo(State.SUCCESS);
    assertThat(captor.getValue().getValue()).isEqualTo(TestConstants.EMAIL);
}
Also used : InOrder(org.mockito.InOrder) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) Resource(com.firebase.ui.auth.data.model.Resource) Test(org.junit.Test)

Example 4 with ActionCodeSettings

use of com.google.firebase.auth.ActionCodeSettings in project FirebaseUI-Android by firebase.

the class AuthUITest method testEmailBuilder_withAnonymousUpgradeAndNotForcingSameDevice_expectThrows.

@Test(expected = IllegalStateException.class)
public void testEmailBuilder_withAnonymousUpgradeAndNotForcingSameDevice_expectThrows() {
    ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder().setUrl(URL).build();
    new IdpConfig.EmailBuilder().enableEmailLinkSignIn().setActionCodeSettings(actionCodeSettings).build();
}
Also used : IdpConfig(com.firebase.ui.auth.AuthUI.IdpConfig) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) Test(org.junit.Test)

Example 5 with ActionCodeSettings

use of com.google.firebase.auth.ActionCodeSettings in project FirebaseUI-Android by firebase.

the class AuthUITest method testEmailBuilder_withValidActionCodeSettings_expectSuccess.

@Test
public void testEmailBuilder_withValidActionCodeSettings_expectSuccess() {
    ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder().setUrl(URL).setHandleCodeInApp(true).build();
    IdpConfig config = new IdpConfig.EmailBuilder().enableEmailLinkSignIn().setActionCodeSettings(actionCodeSettings).setForceSameDevice().build();
    assertEquals(config.getParams().getParcelable(ExtraConstants.ACTION_CODE_SETTINGS), actionCodeSettings);
    assertTrue(config.getParams().getBoolean(ExtraConstants.FORCE_SAME_DEVICE));
    assertEquals(config.getProviderId(), AuthUI.EMAIL_LINK_PROVIDER);
}
Also used : IdpConfig(com.firebase.ui.auth.AuthUI.IdpConfig) ActionCodeSettings(com.google.firebase.auth.ActionCodeSettings) Test(org.junit.Test)

Aggregations

ActionCodeSettings (com.google.firebase.auth.ActionCodeSettings)15 Test (org.junit.Test)8 IdpConfig (com.firebase.ui.auth.AuthUI.IdpConfig)6 IdpResponse (com.firebase.ui.auth.IdpResponse)3 Resource (com.firebase.ui.auth.data.model.Resource)3 InOrder (org.mockito.InOrder)3 AuthUI (com.firebase.ui.auth.AuthUI)2 ArrayList (java.util.ArrayList)2 NonNull (androidx.annotation.NonNull)1 FirebaseAuthActionCodeException (com.google.firebase.auth.FirebaseAuthActionCodeException)1 FirebaseAuthInvalidCredentialsException (com.google.firebase.auth.FirebaseAuthInvalidCredentialsException)1