Search in sources :

Example 1 with AWSCognitoAuthResendSignUpCodeOptions

use of com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions in project amplify-android by aws-amplify.

the class AuthComponentTest method resendSignUpCodeWithOptions.

/**
 * Tests that the resendSignUpCode method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.resendSignUp with
 * the username 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
// Casts final parameter to Callback to differentiate methods
@SuppressWarnings("unchecked")
public void resendSignUpCodeWithOptions() throws AuthException {
    SignUpResult amcResult = new SignUpResult(false, new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME), USER_SUB);
    AWSCognitoAuthResendSignUpCodeOptions.CognitoBuilder options = AWSCognitoAuthResendSignUpCodeOptions.builder();
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put("key", "value");
    options.metadata(metadata);
    AWSCognitoAuthResendSignUpCodeOptions builtOptions = options.build();
    doAnswer(invocation -> {
        Callback<SignUpResult> callback = invocation.getArgument(2);
        callback.onResult(amcResult);
        return null;
    }).when(mobileClient).resendSignUp(any(), any(), (Callback<SignUpResult>) any());
    AuthSignUpResult result = synchronousAuth.resendSignUpCode(USERNAME, builtOptions);
    validateSignUpResult(result, AuthSignUpStep.CONFIRM_SIGN_UP_STEP);
    verify(mobileClient).resendSignUp(eq(USERNAME), eq(metadata), (Callback<SignUpResult>) any());
}
Also used : 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) AWSCognitoAuthResendSignUpCodeOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions) AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) SignUpResult(com.amazonaws.mobile.client.results.SignUpResult) Test(org.junit.Test)

Example 2 with AWSCognitoAuthResendSignUpCodeOptions

use of com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions in project amplify-android by aws-amplify.

the class AWSCognitoAuthPlugin method resendSignUpCode.

@Override
public void resendSignUpCode(@NonNull String username, @NonNull AuthResendSignUpCodeOptions options, @NonNull Consumer<AuthSignUpResult> onSuccess, @NonNull Consumer<AuthException> onException) {
    final Map<String, String> clientMetadata = new HashMap<>();
    if (options instanceof AWSCognitoAuthResendSignUpCodeOptions) {
        AWSCognitoAuthResendSignUpCodeOptions cognitoOptions = (AWSCognitoAuthResendSignUpCodeOptions) options;
        clientMetadata.putAll(cognitoOptions.getMetadata());
    }
    awsMobileClient.resendSignUp(username, 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, "Resend confirmation code failed"));
        }
    });
}
Also used : HashMap(java.util.HashMap) AWSCognitoAuthResendSignUpCodeOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions) 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 AWSCognitoAuthResendSignUpCodeOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions)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