Search in sources :

Example 11 with AuthSignUpResult

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);
}
Also used : AuthSignUpResult(com.amplifyframework.auth.result.AuthSignUpResult) AuthSignUpOptions(com.amplifyframework.auth.options.AuthSignUpOptions) AuthException(com.amplifyframework.auth.AuthException) RandomString(com.amplifyframework.testutils.random.RandomString) Test(org.junit.Test)

Example 12 with AuthSignUpResult

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"));
        }
    });
}
Also used : AuthUserAttribute(com.amplifyframework.auth.AuthUserAttribute) AWSCognitoAuthSignUpOptions(com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignUpOptions) 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)

Example 13 with AuthSignUpResult

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"));
        }
    });
}
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

AuthSignUpResult (com.amplifyframework.auth.result.AuthSignUpResult)13 Test (org.junit.Test)9 SignUpResult (com.amazonaws.mobile.client.results.SignUpResult)8 RandomString (com.amplifyframework.testutils.random.RandomString)7 UserCodeDeliveryDetails (com.amazonaws.mobile.client.results.UserCodeDeliveryDetails)6 AuthException (com.amplifyframework.auth.AuthException)5 HashMap (java.util.HashMap)5 AuthNavigationException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException)3 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)3 AmplifyException (com.amplifyframework.AmplifyException)3 AuthCodeDeliveryDetails (com.amplifyframework.auth.AuthCodeDeliveryDetails)3 AuthNextSignUpStep (com.amplifyframework.auth.result.step.AuthNextSignUpStep)3 JSONException (org.json.JSONException)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 AWSCognitoAuthConfirmSignUpOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthConfirmSignUpOptions)2 AWSCognitoAuthResendSignUpCodeOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendSignUpCodeOptions)2 AWSCognitoAuthSignUpOptions (com.amplifyframework.auth.cognito.options.AWSCognitoAuthSignUpOptions)2 AuthSignUpOptions (com.amplifyframework.auth.options.AuthSignUpOptions)2 AuthSignUpStep (com.amplifyframework.auth.result.step.AuthSignUpStep)2 AuthUser (com.amplifyframework.auth.AuthUser)1