use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class SocialProviderResponseHandlerTest method testSignInNonIdp_failure.
@Test(expected = IllegalStateException.class)
public void testSignInNonIdp_failure() {
mHandler.getOperation().observeForever(mResultObserver);
IdpResponse response = new IdpResponse.Builder(new User.Builder(EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL).build()).build();
mHandler.startSignIn(response);
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class SocialProviderResponseHandlerTest method testSignInResponse_failure.
@Test
public void testSignInResponse_failure() {
mHandler.getOperation().observeForever(mResultObserver);
IdpResponse response = IdpResponse.from(new Exception("Failure"));
mHandler.startSignIn(response);
verify(mResultObserver).onChanged(argThat(ResourceMatchers.isFailure()));
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class SocialProviderResponseHandlerTest method testSignInIdp_anonymousUserUpgradeEnabledAndExistingUserWithSameIdp_expectMergeFailure.
@Test
public void testSignInIdp_anonymousUserUpgradeEnabledAndExistingUserWithSameIdp_expectMergeFailure() {
mHandler.getOperation().observeForever(mResultObserver);
setupAnonymousUpgrade();
when(mMockAuth.getCurrentUser().linkWithCredential(any(AuthCredential.class))).thenReturn(AutoCompleteTask.forFailure(new FirebaseAuthUserCollisionException("foo", "bar")));
// Case 1: Anon user signing in with a Google credential that belongs to an existing user.
when(mMockAuth.fetchSignInMethodsForEmail(any(String.class))).thenReturn(AutoCompleteTask.forSuccess(new FakeSignInMethodQueryResult(Arrays.asList(GoogleAuthProvider.GOOGLE_SIGN_IN_METHOD, 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());
FirebaseAuthAnonymousUpgradeException e = (FirebaseAuthAnonymousUpgradeException) resolveCaptor.getValue().getException();
assertThat(e.getResponse().getCredentialForLinking()).isNotNull();
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class RegisterEmailFragment method registerUser.
private void registerUser(final String email, final String name, final String password) {
mHelper.getFirebaseAuth().createUserWithEmailAndPassword(email, password).addOnFailureListener(new TaskFailureLogger(TAG, "Error creating user")).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
// Set display name
UserProfileChangeRequest changeNameRequest = new UserProfileChangeRequest.Builder().setDisplayName(name).setPhotoUri(mUser.getPhotoUri()).build();
final FirebaseUser user = authResult.getUser();
user.updateProfile(changeNameRequest).addOnFailureListener(new TaskFailureLogger(TAG, "Error setting display name")).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// This executes even if the name change fails, since
// the account creation succeeded and we want to save
// the credential to SmartLock (if enabled).
mHelper.saveCredentialsOrFinish(mSaveSmartLock, getActivity(), user, password, new IdpResponse(EmailAuthProvider.PROVIDER_ID, email));
}
});
}
}).addOnFailureListener(getActivity(), new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mHelper.dismissDialog();
if (e instanceof FirebaseAuthWeakPasswordException) {
// Password too weak
mPasswordInput.setError(getResources().getQuantityString(R.plurals.error_weak_password, R.integer.min_password_length));
} else if (e instanceof FirebaseAuthInvalidCredentialsException) {
// Email address is malformed
mEmailInput.setError(getString(R.string.invalid_email_address));
} else if (e instanceof FirebaseAuthUserCollisionException) {
// Collision with existing user email, it should be very hard for
// the user to even get to this error due to CheckEmailFragment.
mEmailInput.setError(getString(R.string.error_user_collision));
} else {
// General error message, this branch should not be invoked but
// covers future API changes
mEmailInput.setError(getString(R.string.email_account_creation_error));
}
}
});
}
use of com.firebase.ui.auth.IdpResponse in project FirebaseUI-Android by firebase.
the class WelcomeBackPasswordPrompt method next.
private void next(final String email, final String password) {
// Check for null or empty password
if (TextUtils.isEmpty(password)) {
mPasswordLayout.setError(getString(R.string.required_field));
return;
} else {
mPasswordLayout.setError(null);
}
mActivityHelper.showLoadingDialog(R.string.progress_dialog_signing_in);
final FirebaseAuth firebaseAuth = mActivityHelper.getFirebaseAuth();
// Sign in with known email and the password provided
firebaseAuth.signInWithEmailAndPassword(email, password).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with email and password")).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
AuthCredential authCredential = AuthCredentialHelper.getAuthCredential(mIdpResponse);
// Otherwise, the user has an email account that we need to link to an idp.
if (authCredential == null) {
mActivityHelper.saveCredentialsOrFinish(mSaveSmartLock, authResult.getUser(), password, new IdpResponse(EmailAuthProvider.PROVIDER_ID, email));
} else {
authResult.getUser().linkWithCredential(authCredential).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with credential " + authCredential.getProvider())).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
mActivityHelper.saveCredentialsOrFinish(mSaveSmartLock, authResult.getUser(), mIdpResponse);
}
});
}
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mActivityHelper.dismissDialog();
String error = e.getLocalizedMessage();
mPasswordLayout.setError(error);
}
});
}
Aggregations