Search in sources :

Example 1 with SignUpRequest

use of com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest in project aws-sdk-android by aws-amplify.

the class CognitoUserPool method signUpInternal.

/**
 * Internal method to sign-up a new user in Cognito Identity Provider user pool.
 *
 * @param userId            REQUIRED: The new user userId.
 * @param password          REQUIRED: Password you want to associate to this use.
 * @param userAttributes    REQUIRED: User attributes.
 * @param validationData    REQUIRED: Validation key value pairs, these will be passed to pre
 *                          and post registration lambda functions.
 * @param clientMetadata    Client metadata for lambda function for user registration
 * @return SignUpResult
 */
private SignUpResult signUpInternal(String userId, String password, CognitoUserAttributes userAttributes, Map<String, String> validationData, final Map<String, String> clientMetadata) {
    // Create a list of {@link AttributeType} from {@code userAttributes}
    List<AttributeType> validationDataList = null;
    if (validationData != null) {
        validationDataList = new ArrayList<AttributeType>();
        for (final Map.Entry<String, String> data : validationData.entrySet()) {
            final AttributeType validation = new AttributeType();
            validation.setName(data.getKey());
            validation.setValue(data.getValue());
            validationDataList.add(validation);
        }
    }
    // Generate Client secret hash
    secretHash = CognitoSecretHash.getSecretHash(userId, clientId, clientSecret);
    // Create User registration request
    final SignUpRequest signUpUserRequest = new SignUpRequest().withUsername(userId).withPassword(password).withClientId(clientId).withSecretHash(secretHash).withUserAttributes(userAttributes.getAttributesList()).withValidationData(validationDataList).withClientMetadata(clientMetadata).withUserContextData(getUserContextData(userId));
    String ppEndpoint = getPinpointEndpointId();
    if (ppEndpoint != null) {
        AnalyticsMetadataType amd = new AnalyticsMetadataType();
        amd.setAnalyticsEndpointId(ppEndpoint);
        signUpUserRequest.setAnalyticsMetadata(amd);
    }
    return client.signUp(signUpUserRequest);
}
Also used : AnalyticsMetadataType(com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType) AttributeType(com.amazonaws.services.cognitoidentityprovider.model.AttributeType) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) Map(java.util.Map)

Example 2 with SignUpRequest

use of com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderUserPoolTest method signUpUserInCurrentThread.

@Test
public void signUpUserInCurrentThread() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
    expected_result_boolean = true;
    testPool.signUp(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, null, new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            // Verify the arguments
            ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
            verify(mockCSIClient).signUp(argumentCaptor.capture());
            SignUpRequest requestSent = argumentCaptor.getValue();
            assertNotNull(requestSent);
            assertEquals(TEST_USER_NAME, requestSent.getUsername());
            assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
            assertNotNull(requestSent.getUserAttributes());
            assertEquals(2, requestSent.getUserAttributes().size());
            assertNull(requestSent.getValidationData());
            // Verify results
            assertNotNull(user);
            assertNotNull(signUpResult.getUserConfirmed());
            assertNotNull(signUpResult.getCodeDeliveryDetails());
            assertEquals(TEST_USER_NAME, user.getUserId());
            assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNull(exception);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ArgumentCaptor(org.mockito.ArgumentCaptor) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) Test(org.junit.Test)

Example 3 with SignUpRequest

use of com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderUserPoolTest method signUpUserWithoutPPInCurrentThread.

@Test
public void signUpUserWithoutPPInCurrentThread() throws Exception {
    // Test shared Pinpoint context
    awsKeyValueStorageUtility.put(PP_UNIQUE_ID_KEY, TEST_PP_ENDPOINT_1);
    // Test new user pool creation with PP app id.
    CognitoUserPool testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
    expected_result_boolean = true;
    testPool.signUp(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, null, new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            // Verify the arguments
            ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
            verify(mockCSIClient).signUp(argumentCaptor.capture());
            SignUpRequest requestSent = argumentCaptor.getValue();
            assertNotNull(requestSent);
            assertEquals(TEST_USER_NAME, requestSent.getUsername());
            assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
            assertNotNull(requestSent.getUserAttributes());
            assertEquals(2, requestSent.getUserAttributes().size());
            assertNull(requestSent.getValidationData());
            assertNull(requestSent.getAnalyticsMetadata());
            // Verify results
            assertNotNull(user);
            assertNotNull(signUpResult.getUserConfirmed());
            assertNotNull(signUpResult.getCodeDeliveryDetails());
            assertEquals(TEST_USER_NAME, user.getUserId());
            assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNull(exception);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ArgumentCaptor(org.mockito.ArgumentCaptor) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) Test(org.junit.Test)

Example 4 with SignUpRequest

use of com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderUserPoolTest method signUpUserWithPPInCurrentThread.

@Test
public void signUpUserWithPPInCurrentThread() throws Exception {
    // Test shared Pinpoint context
    ApplicationProvider.getApplicationContext().getSharedPreferences(TEST_PP_APP_ID_1 + PP_PREFERENCES_AND_FILE_MANAGER_SUFFIX, Context.MODE_PRIVATE).edit().putString(PP_UNIQUE_ID_KEY, TEST_PP_ENDPOINT_1).apply();
    // Test new user pool creation with PP app id.
    CognitoUserPool testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient, TEST_PP_APP_ID_1);
    doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
    expected_result_boolean = true;
    testPool.signUp(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, null, new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            // Verify the arguments
            ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
            verify(mockCSIClient).signUp(argumentCaptor.capture());
            SignUpRequest requestSent = argumentCaptor.getValue();
            assertNotNull(requestSent);
            assertEquals(TEST_USER_NAME, requestSent.getUsername());
            assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
            assertNotNull(requestSent.getUserAttributes());
            assertEquals(2, requestSent.getUserAttributes().size());
            assertNull(requestSent.getValidationData());
            assertNotNull(requestSent.getAnalyticsMetadata());
            assertEquals(TEST_PP_ENDPOINT_1, requestSent.getAnalyticsMetadata().getAnalyticsEndpointId());
            // Verify results
            assertNotNull(user);
            assertNotNull(signUpResult.getUserConfirmed());
            assertNotNull(signUpResult.getCodeDeliveryDetails());
            assertEquals(TEST_USER_NAME, user.getUserId());
            assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNull(exception);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ArgumentCaptor(org.mockito.ArgumentCaptor) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) Test(org.junit.Test)

Example 5 with SignUpRequest

use of com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderUserPoolTest method signUpUserInBackgroundThread.

@Test
public void signUpUserInBackgroundThread() throws Exception {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    doReturn(TEST_REGISTER_USER_RESPONSE).when(mockCSIClient).signUp(any(SignUpRequest.class));
    expected_result_boolean = true;
    testPool.signUpInBackground(TEST_USER_NAME, TEST_USER_PASSWORD, TEST_IN_USER_ATTRIBUTES_LIST, TEST_IN_VALIDATION_DATA, new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            // Verify the arguments
            ArgumentCaptor<SignUpRequest> argumentCaptor = ArgumentCaptor.forClass(SignUpRequest.class);
            verify(mockCSIClient).signUp(argumentCaptor.capture());
            SignUpRequest requestSent = argumentCaptor.getValue();
            assertNotNull(requestSent);
            assertEquals(TEST_USER_NAME, requestSent.getUsername());
            assertEquals(TEST_USER_PASSWORD, requestSent.getPassword());
            assertNotNull(requestSent.getUserAttributes());
            assertEquals(2, requestSent.getUserAttributes().size());
            assertNotNull(requestSent.getValidationData());
            assertEquals(3, requestSent.getValidationData().size());
            assertNotNull(user);
            assertNotNull(signUpResult.getUserConfirmed());
            assertNotNull(signUpResult.getCodeDeliveryDetails());
            assertEquals(TEST_USER_NAME, user.getUserId());
            assertEquals(signUpResult.getUserConfirmed(), expected_result_boolean);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNull(exception);
        }
    });
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ArgumentCaptor(org.mockito.ArgumentCaptor) SignUpHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler) SignUpRequest(com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) UnexpectedLambdaException(com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) SignUpResult(com.amazonaws.services.cognitoidentityprovider.model.SignUpResult) Test(org.junit.Test)

Aggregations

SignUpRequest (com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest)5 CognitoUser (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser)4 CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)4 SignUpHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler)4 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)4 ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)4 SignUpResult (com.amazonaws.services.cognitoidentityprovider.model.SignUpResult)4 UnexpectedLambdaException (com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException)4 Test (org.junit.Test)4 ArgumentCaptor (org.mockito.ArgumentCaptor)4 AnalyticsMetadataType (com.amazonaws.services.cognitoidentityprovider.model.AnalyticsMetadataType)1 AttributeType (com.amazonaws.services.cognitoidentityprovider.model.AttributeType)1 Map (java.util.Map)1