use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class SocialProviderResponseHandlerTest method testSignInIdp_anonymousUserUpgradeEnabledAndExistingIdpUserWithDifferentIdp_expectMergeFailure.
@Test
public void testSignInIdp_anonymousUserUpgradeEnabledAndExistingIdpUserWithDifferentIdp_expectMergeFailure() {
mHandler.getOperation().observeForever(mResultObserver);
setupAnonymousUpgrade();
when(mMockAuth.getCurrentUser().linkWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forFailure(new FirebaseAuthUserCollisionException("foo", "bar")));
// Case 2 & 3: trying to link with an account that has 1 idp, which is different from the
// one that we're trying to log in with
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.getCurrentUser()).linkWithCredential(any(AuthCredential.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());
// Make sure that we are trying to start the WelcomeBackIdpPrompt activity
IntentRequiredException e = ((IntentRequiredException) resolveCaptor.getValue().getException());
assertThat(e.getIntent().getComponent().getClassName()).isEqualTo(WelcomeBackIdpPrompt.class.toString().split(" ")[1]);
assertThat(IdpResponse.fromResultIntent(e.getIntent())).isEqualTo(response);
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class SocialProviderResponseHandlerTest method testSignInIdp_anonymousUserUpgradeEnabledAndExistingPasswordUserWithDifferentIdp_expectMergeFailure.
@Test
public void testSignInIdp_anonymousUserUpgradeEnabledAndExistingPasswordUserWithDifferentIdp_expectMergeFailure() {
mHandler.getOperation().observeForever(mResultObserver);
setupAnonymousUpgrade();
when(mMockAuth.getCurrentUser().linkWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forFailure(new FirebaseAuthUserCollisionException("foo", "bar")));
// Case 2 & 3: trying to link with an account that has 1 password provider and logging in
// with an idp that has the same email
when(mMockAuth.fetchSignInMethodsForEmail(any(String.class))).thenReturn(AutoCompleteTask.forSuccess(new FakeSignInMethodQueryResult(Collections.singletonList(EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD))));
IdpResponse response = new IdpResponse.Builder(new User.Builder(FacebookAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).setToken(TestConstants.TOKEN).setSecret(TestConstants.SECRET).build();
mHandler.startSignIn(response);
verify(mMockAuth.getCurrentUser()).linkWithCredential(any(AuthCredential.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());
// Make sure that we are trying to start the WelcomeBackIdpPrompt activity
IntentRequiredException e = ((IntentRequiredException) resolveCaptor.getValue().getException());
assertThat(e.getIntent().getComponent().getClassName()).isEqualTo(WelcomeBackPasswordPrompt.class.toString().split(" ")[1]);
assertThat(IdpResponse.fromResultIntent(e.getIntent())).isEqualTo(response);
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class WelcomeBackPasswordHandlerTest method testSignIn_linksIdpCredential.
@Test
public void testSignIn_linksIdpCredential() {
mHandler.getOperation().observeForever(mResponseObserver);
// Fake social response from Facebook
User user = new User.Builder(FacebookAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build();
IdpResponse response = new IdpResponse.Builder(user).setToken(TestConstants.TOKEN).setSecret(TestConstants.SECRET).build();
AuthCredential credential = FacebookAuthProvider.getCredential(TestConstants.TOKEN);
// Mock sign in to always succeed
when(mMockAuth.signInWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD)).thenReturn(AutoCompleteTask.forSuccess(FakeAuthResult.INSTANCE));
// Mock linking to always succeed
when(FakeAuthResult.INSTANCE.getUser().linkWithCredential(credential)).thenReturn(new AutoContinueTask<>(FakeAuthResult.INSTANCE, FakeAuthResult.INSTANCE, true, null));
// Mock smartlock save to always succeed
when(mMockCredentials.save(any(Credential.class))).thenReturn(AutoCompleteTask.forSuccess(null));
// Kick off the sign in flow
mHandler.startSignIn(TestConstants.EMAIL, TestConstants.PASSWORD, response, credential);
// Verify that we get a loading event
verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isLoading()));
// Verify that sign in is called with the right arguments
verify(mMockAuth).signInWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD);
// Verify that account linking is attempted
verify(FakeAuthResult.INSTANCE.getUser()).linkWithCredential(credential);
// Verify that we get a success event
verify(mResponseObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class EmailLinkSendEmailHandlerTest method testSendSignInLinkToEmail_linkingFlow_expectSuccess.
@Test
public void testSendSignInLinkToEmail_linkingFlow_expectSuccess() {
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()));
IdpResponse idpResponseForLinking = buildFacebookIdpResponseForLinking();
mHandler.sendSignInLinkToEmail(TestConstants.EMAIL, actionCodeSettings, idpResponseForLinking, forceSameDevice);
ArgumentCaptor<ActionCodeSettings> acsCaptor = ArgumentCaptor.forClass(ActionCodeSettings.class);
verify(mMockAuth).sendSignInLinkToEmail(eq(TestConstants.EMAIL), acsCaptor.capture());
validateSessionIdAddedToContinueUrl(acsCaptor.getValue(), idpResponseForLinking.getProviderType(), 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.firebase.ui.auth.IdpResponse in project quickstart-android by firebase.
the class MainActivity method onSignInResult.
private void onSignInResult(FirebaseAuthUIAuthenticationResult result) {
if (result.getResultCode() == RESULT_OK) {
showSnackbar("Signed in.");
} else {
showSnackbar("Error signing in.");
IdpResponse response = result.getIdpResponse();
Log.w(TAG, "signIn", response.getError());
}
}
Aggregations