Search in sources :

Example 1 with AWSCognitoAuthConfirmSignUpOptions

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());
}
Also used : AWSCognitoAuthConfirmSignUpOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthConfirmSignUpOptions) HashMap(java.util.HashMap) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) RandomString(com.amplifyframework.testutils.random.RandomString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) SignUpResult(com.amazonaws.mobile.client.results.SignUpResult) Test(org.junit.Test)

Example 2 with AWSCognitoAuthConfirmSignUpOptions

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"));
        }
    });
}
Also used : AWSCognitoAuthConfirmSignUpOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthConfirmSignUpOptions) HashMap(java.util.HashMap) AuthException(com.amplifyframework.auth.AuthException) JSONException(org.json.JSONException) AmplifyException(com.amplifyframework.AmplifyException) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) AuthNavigationException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) SignUpResult(com.amazonaws.mobile.client.results.SignUpResult)

Aggregations

SignUpResult (com.amazonaws.mobile.client.results.SignUpResult)2 AWSCognitoAuthConfirmSignUpOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthConfirmSignUpOptions)2 AuthSignUpResult (com.amplifyframework.auth.result.AuthSignUpResult)2 HashMap (java.util.HashMap)2 UserCodeDeliveryDetails (com.amazonaws.mobile.client.results.UserCodeDeliveryDetails)1 AuthNavigationException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException)1 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)1 AmplifyException (com.amplifyframework.AmplifyException)1 AuthException (com.amplifyframework.auth.AuthException)1 RandomString (com.amplifyframework.testutils.random.RandomString)1 JSONException (org.json.JSONException)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1