use of com.firebase.ui.auth.data.model.PendingIntentRequiredException in project FirebaseUI-Android by firebase.
the class SmartLockHandlerTest method testSaveCredentials_resolution.
@Test
public void testSaveCredentials_resolution() {
mHandler.getOperation().observeForever(mResultObserver);
// Mock credentials to throw an RAE
ResolvableApiException mockRae = mock(ResolvableApiException.class);
when(mMockCredentials.save(any(Credential.class))).thenReturn(AutoCompleteTask.forFailure(mockRae));
// Kick off save
mHandler.saveCredentials(TestHelper.getMockFirebaseUser(), TestConstants.PASSWORD, null);
InOrder inOrder = inOrder(mResultObserver);
inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isLoading()));
// Make sure we get a resolution
ArgumentCaptor<Resource<IdpResponse>> resolveCaptor = ArgumentCaptor.forClass(Resource.class);
inOrder.verify(mResultObserver).onChanged(resolveCaptor.capture());
// Call activity result
PendingIntentRequiredException e = ((PendingIntentRequiredException) resolveCaptor.getValue().getException());
mHandler.onActivityResult(e.getRequestCode(), Activity.RESULT_OK);
// Make sure we get success
inOrder.verify(mResultObserver).onChanged(argThat(ResourceMatchers.isSuccess()));
}
use of com.firebase.ui.auth.data.model.PendingIntentRequiredException 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())));
}
});
}
use of com.firebase.ui.auth.data.model.PendingIntentRequiredException in project FirebaseUI-Android by firebase.
the class FlowUtils method unhandled.
public static boolean unhandled(@NonNull FragmentBase fragment, @Nullable Exception e) {
if (e instanceof IntentRequiredException) {
IntentRequiredException typed = (IntentRequiredException) e;
fragment.startActivityForResult(typed.getIntent(), typed.getRequestCode());
return false;
} else if (e instanceof PendingIntentRequiredException) {
PendingIntentRequiredException typed = (PendingIntentRequiredException) e;
startIntentSenderForResult(fragment, typed.getPendingIntent(), typed.getRequestCode());
return false;
}
return true;
}
use of com.firebase.ui.auth.data.model.PendingIntentRequiredException in project FirebaseUI-Android by firebase.
the class FlowUtils method unhandled.
public static boolean unhandled(@NonNull HelperActivityBase activity, @Nullable Exception e) {
if (e instanceof IntentRequiredException) {
IntentRequiredException typed = (IntentRequiredException) e;
activity.startActivityForResult(typed.getIntent(), typed.getRequestCode());
return false;
} else if (e instanceof PendingIntentRequiredException) {
PendingIntentRequiredException typed = (PendingIntentRequiredException) e;
startIntentSenderForResult(activity, typed.getPendingIntent(), typed.getRequestCode());
return false;
}
return true;
}
use of com.firebase.ui.auth.data.model.PendingIntentRequiredException in project FirebaseUI-Android by firebase.
the class SignInKickstarter method start.
public void start() {
if (!TextUtils.isEmpty(getArguments().emailLink)) {
setResult(Resource.forFailure(new IntentRequiredException(EmailLinkCatcherActivity.createIntent(getApplication(), getArguments()), RequestCodes.EMAIL_FLOW)));
return;
}
// Signing in with Generic IDP puts the app in the background - it can be reclaimed by the
// OS during the sign in flow.
Task<AuthResult> pendingResultTask = getAuth().getPendingAuthResult();
if (pendingResultTask != null) {
pendingResultTask.addOnSuccessListener(authResult -> {
final IdpResponse response = new IdpResponse.Builder(new User.Builder(authResult.getCredential().getProvider(), authResult.getUser().getEmail()).build()).build();
handleSuccess(response, authResult);
}).addOnFailureListener(e -> setResult(Resource.forFailure(e)));
return;
}
// Only support password credentials if email auth is enabled
boolean supportPasswords = ProviderUtils.getConfigFromIdps(getArguments().providers, EmailAuthProvider.PROVIDER_ID) != null;
List<String> accountTypes = getCredentialAccountTypes();
// If the request will be empty, avoid the step entirely
boolean willRequestCredentials = supportPasswords || accountTypes.size() > 0;
if (getArguments().enableCredentials && willRequestCredentials) {
setResult(Resource.forLoading());
GoogleApiUtils.getCredentialsClient(getApplication()).request(new CredentialRequest.Builder().setPasswordLoginSupported(supportPasswords).setAccountTypes(accountTypes.toArray(new String[accountTypes.size()])).build()).addOnCompleteListener(task -> {
try {
handleCredential(task.getResult(ApiException.class).getCredential());
} catch (ResolvableApiException e) {
if (e.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
setResult(Resource.forFailure(new PendingIntentRequiredException(e.getResolution(), RequestCodes.CRED_HINT)));
} else {
startAuthMethodChoice();
}
} catch (ApiException e) {
startAuthMethodChoice();
}
});
} else {
startAuthMethodChoice();
}
}
Aggregations