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.");
}
}
}
});
}
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();
}
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);
}
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();
}
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);
}
Aggregations