use of com.firebase.ui.auth.FirebaseUiException in project FirebaseUI-Android by firebase.
the class EmailLinkSignInHandlerTest method testStartSignIn_differentDeviceLinkWithNoSessionId_expectInvalidLinkError.
@Test
@SuppressWarnings("all")
public void testStartSignIn_differentDeviceLinkWithNoSessionId_expectInvalidLinkError() {
initializeHandlerWithSessionInfo(null, null, null, true);
mHandler.getOperation().observeForever(mResponseObserver);
when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true);
mHandler.startSignIn();
verify(mMockAuth).isSignInWithEmailLink(any(String.class));
ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class);
InOrder inOrder = inOrder(mResponseObserver);
inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading()));
inOrder.verify(mResponseObserver).onChanged(captor.capture());
FirebaseUiException exception = (FirebaseUiException) captor.getValue().getException();
assertThat(exception).isNotNull();
assertThat(exception.getErrorCode()).isEqualTo(ErrorCodes.INVALID_EMAIL_LINK_ERROR);
}
use of com.firebase.ui.auth.FirebaseUiException in project FirebaseUI-Android by firebase.
the class EmailLinkSignInHandlerTest method testStartSignIn_differentDeviceLinkWithValidSessionInfo_expectInvalidLinkError.
@Test
@SuppressWarnings("all")
public void testStartSignIn_differentDeviceLinkWithValidSessionInfo_expectInvalidLinkError() {
String differentSessionId = SessionUtils.generateRandomAlphaNumericString(10);
initializeHandlerWithSessionInfo(differentSessionId, null, null, false);
mHandler.getOperation().observeForever(mResponseObserver);
when(mMockAuth.isSignInWithEmailLink(any(String.class))).thenReturn(true);
when(mMockAuth.checkActionCode(any(String.class))).thenReturn(AutoCompleteTask.<ActionCodeResult>forFailure(new Exception("foo")));
mHandler.startSignIn();
verify(mMockAuth).isSignInWithEmailLink(any(String.class));
verify(mMockAuth).checkActionCode(any(String.class));
ArgumentCaptor<Resource<IdpResponse>> captor = ArgumentCaptor.forClass(Resource.class);
InOrder inOrder = inOrder(mResponseObserver);
inOrder.verify(mResponseObserver).onChanged(argThat(ResourceMatchers.<IdpResponse>isLoading()));
inOrder.verify(mResponseObserver).onChanged(captor.capture());
FirebaseUiException exception = (FirebaseUiException) captor.getValue().getException();
assertThat(exception).isNotNull();
assertThat(exception.getErrorCode()).isEqualTo(ErrorCodes.INVALID_EMAIL_LINK_ERROR);
}
use of com.firebase.ui.auth.FirebaseUiException in project FirebaseUI-Android by firebase.
the class SocialProviderResponseHandler method startSignIn.
public void startSignIn(@NonNull final IdpResponse response) {
if (!response.isSuccessful() && !response.isRecoverableErrorResponse()) {
setResult(Resource.forFailure(response.getError()));
return;
}
if (isEmailOrPhoneProvider(response.getProviderType())) {
throw new IllegalStateException("This handler cannot be used with email or phone providers");
}
setResult(Resource.forLoading());
// a credential made from the id token/access token cannot be used to sign-in.
if (response.hasCredentialForLinking()) {
handleGenericIdpLinkingFlow(response);
return;
}
final AuthCredential credential = ProviderUtils.getAuthCredential(response);
AuthOperationManager.getInstance().signInAndLinkWithCredential(getAuth(), getArguments(), credential).continueWithTask(new ProfileMerger(response)).addOnSuccessListener(result -> handleSuccess(response, result)).addOnFailureListener(e -> {
// For some reason disabled users can hit FirebaseAuthUserCollisionException
// so we have to handle this special case.
boolean isDisabledUser = (e instanceof FirebaseAuthInvalidUserException);
if (e instanceof FirebaseAuthException) {
FirebaseAuthException authEx = (FirebaseAuthException) e;
FirebaseAuthError fae = FirebaseAuthError.fromException(authEx);
if (fae == FirebaseAuthError.ERROR_USER_DISABLED) {
isDisabledUser = true;
}
}
if (isDisabledUser) {
setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.ERROR_USER_DISABLED)));
} else if (e instanceof FirebaseAuthUserCollisionException) {
final String email = response.getEmail();
if (email == null) {
setResult(Resource.forFailure(e));
return;
}
// There can be a collision due to:
// CASE 1: Anon user signing in with a credential that belongs to an
// existing user.
// CASE 2: non - anon user signing in with a credential that does not
// belong to an existing user, but the email matches an existing user
// that has another social IDP. We need to link this new IDP to this
// existing user.
// CASE 3: CASE 2 with an anonymous user. We link the new IDP to the
// same account before handling invoking a merge failure.
ProviderUtils.fetchSortedProviders(getAuth(), getArguments(), email).addOnSuccessListener(providers -> {
if (providers.contains(response.getProviderType())) {
// Case 1
handleMergeFailure(credential);
} else if (providers.isEmpty()) {
setResult(Resource.forFailure(new FirebaseUiException(ErrorCodes.DEVELOPER_ERROR, "No supported providers.")));
} else {
// Case 2 & 3 - we need to link
startWelcomeBackFlowForLinking(providers.get(0), response);
}
}).addOnFailureListener(e1 -> setResult(Resource.forFailure(e1)));
}
});
}
use of com.firebase.ui.auth.FirebaseUiException in project FirebaseUI-Android by firebase.
the class SocialProviderResponseHandler method onActivityResult.
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == RequestCodes.ACCOUNT_LINK_FLOW) {
IdpResponse response = IdpResponse.fromResultIntent(data);
if (resultCode == Activity.RESULT_OK) {
setResult(Resource.forSuccess(response));
} else {
Exception e;
if (response == null) {
e = new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR, "Link canceled by user.");
} else {
e = response.getError();
}
setResult(Resource.forFailure(e));
}
}
}
use of com.firebase.ui.auth.FirebaseUiException 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())));
}
});
}
Aggregations