use of com.amplifyframework.auth.result.AuthSignUpResult in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testSignUpFails.
/**
* Validates that a sign-up failure are passed through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testSignUpFails() throws InterruptedException {
String username = RandomString.string();
String password = RandomString.string();
AuthSignUpOptions options = AuthSignUpOptions.builder().build();
// Arrange a callback on the failure consumer
AuthException failure = new AuthException("Sign up", "has failed");
doAnswer(invocation -> {
// 0 = username, 1 = pass, 2 = options, 3 = onSuccess, 4 = onFailure
int positionOfFailureConsumer = 4;
Consumer<AuthException> onFailure = invocation.getArgument(positionOfFailureConsumer);
onFailure.accept(failure);
return null;
}).when(delegate).signUp(eq(username), eq(password), eq(options), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthSignUpResult> observer = auth.signUp(username, password, options).test();
// Assert: error is furnished via Rx single.
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoValues().assertError(failure);
}
use of com.amplifyframework.auth.result.AuthSignUpResult in project amplify-android by aws-amplify.
the class AWSCognitoAuthPlugin method signUp.
@Override
public void signUp(@NonNull String username, @NonNull String password, @NonNull AuthSignUpOptions options, @NonNull final Consumer<AuthSignUpResult> onSuccess, @NonNull final Consumer<AuthException> onException) {
Map<String, String> userAttributes = new HashMap<>();
Map<String, String> validationData = new HashMap<>();
Map<String, String> clientMetadata = new HashMap<>();
if (options.getUserAttributes() != null) {
for (AuthUserAttribute attribute : options.getUserAttributes()) {
userAttributes.put(attribute.getKey().getKeyString(), attribute.getValue());
}
}
if (options instanceof AWSCognitoAuthSignUpOptions) {
validationData = ((AWSCognitoAuthSignUpOptions) options).getValidationData();
clientMetadata = ((AWSCognitoAuthSignUpOptions) options).getClientMetadata();
}
awsMobileClient.signUp(username, password, userAttributes, validationData, clientMetadata, new Callback<SignUpResult>() {
@Override
public void onResult(SignUpResult result) {
onSuccess.accept(convertSignUpResult(result, username));
}
@Override
public void onError(Exception error) {
onException.accept(CognitoAuthExceptionConverter.lookup(error, "Sign up failed"));
}
});
}
use of com.amplifyframework.auth.result.AuthSignUpResult in project amplify-android by aws-amplify.
the class AWSCognitoAuthPlugin method confirmSignUp.
@Override
public void confirmSignUp(@NonNull String username, @NonNull String confirmationCode, @NonNull AuthConfirmSignUpOptions options, @NonNull final Consumer<AuthSignUpResult> onSuccess, @NonNull final Consumer<AuthException> onException) {
final Map<String, String> clientMetadata = new HashMap<>();
if (options instanceof AWSCognitoAuthConfirmSignUpOptions) {
AWSCognitoAuthConfirmSignUpOptions cognitoOptions = (AWSCognitoAuthConfirmSignUpOptions) options;
clientMetadata.putAll(cognitoOptions.getClientMetadata());
}
awsMobileClient.confirmSignUp(username, confirmationCode, clientMetadata, new Callback<SignUpResult>() {
@Override
public void onResult(SignUpResult result) {
onSuccess.accept(convertSignUpResult(result, username));
}
@Override
public void onError(Exception error) {
onException.accept(CognitoAuthExceptionConverter.lookup(error, "Confirm sign up failed"));
}
});
}
Aggregations