use of com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignUpOptions in project amplify-android by aws-amplify.
the class AuthComponentTest method signUp.
/**
* Tests that the signUp method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.signUp() with the username
* and password it received and, if included, the userAttributes and validationData sent in the options object.
* Also ensures that in the onResult case, the success callback receives a valid AuthSignUpResult.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void signUp() throws AuthException {
SignUpResult amcResult = new SignUpResult(false, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
doAnswer(invocation -> {
Callback<SignUpResult> callback = invocation.getArgument(5);
callback.onResult(amcResult);
return null;
}).when(mobileClient).signUp(any(), any(), any(), any(), any(), Mockito.<Callback<SignUpResult>>any());
AWSCognitoAuthSignUpOptions options = AWSCognitoAuthSignUpOptions.builder().userAttribute(AuthUserAttributeKey.email(), ATTRIBUTE_VAL).validationData(VALIDATIONDATA).clientMetadata(CLIENTMETADATA).build();
AuthSignUpResult result = synchronousAuth.signUp(USERNAME, PASSWORD, options);
validateSignUpResult(result, AuthSignUpStep.CONFIRM_SIGN_UP_STEP);
Map<String, String> expectedAttributeMap = Collections.singletonMap(ATTRIBUTE_KEY, ATTRIBUTE_VAL);
verify(mobileClient).signUp(eq(USERNAME), eq(PASSWORD), eq(expectedAttributeMap), eq(VALIDATIONDATA), eq(CLIENTMETADATA), Mockito.<Callback<SignUpResult>>any());
}
use of com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignUpOptions 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"));
}
});
}
Aggregations