use of com.amplifyframework.auth.cognito.options.AWSCognitoAuthConfirmSignUpOptions in project amplify-android by aws-amplify.
the class AuthComponentTest method confirmSignUpWithOptions.
/**
* Tests that the confirmSignUp method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.confirmSignUp with
* the username and confirmation code and options it received.
* 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 confirmSignUpWithOptions() throws AuthException {
SignUpResult amcResult = new SignUpResult(true, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
AWSCognitoAuthConfirmSignUpOptions.CognitoBuilder options = AWSCognitoAuthConfirmSignUpOptions.builder();
Map<String, String> clientMetadata = new HashMap<String, String>();
clientMetadata.put("testKey", "testValue");
options.clientMetadata(clientMetadata);
AWSCognitoAuthConfirmSignUpOptions builtOptions = options.build();
doAnswer(invocation -> {
Callback<SignUpResult> callback = invocation.getArgument(3);
callback.onResult(amcResult);
return null;
}).when(mobileClient).confirmSignUp(any(), any(), any(), Mockito.<Callback<SignUpResult>>any());
AuthSignUpResult result = synchronousAuth.confirmSignUp(USERNAME, CONFIRMATION_CODE, builtOptions);
validateSignUpResult(result, AuthSignUpStep.DONE);
verify(mobileClient).confirmSignUp(eq(USERNAME), eq(CONFIRMATION_CODE), eq(clientMetadata), Mockito.<Callback<SignUpResult>>any());
}
use of com.amplifyframework.auth.cognito.options.AWSCognitoAuthConfirmSignUpOptions 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