Search in sources :

Example 36 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class CognitoUserPoolsSignInProvider method initialize.

/**
 * {@inheritDoc}
 */
@Override
public void initialize(final Context context, final AWSConfiguration awsConfiguration) {
    this.context = context;
    this.awsConfiguration = awsConfiguration;
    Log.d(LOG_TAG, "Initializing Cognito User Pools");
    this.cognitoUserPool = new CognitoUserPool(context, awsConfiguration);
    cognitoLoginKey = "cognito-idp." + getValueFromConfig("Region") + ".amazonaws.com/" + cognitoUserPool.getUserPoolId();
}
Also used : CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)

Example 37 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderUpdateDetailsTest method updateUserAttributeInBackgroundWithCachedTokensServiceException.

// Get user attributes - in background
@Test
public void updateUserAttributeInBackgroundWithCachedTokensServiceException() {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Set mock result for the change password request API call
    InvalidParameterException exception = new InvalidParameterException("failed");
    doThrow(exception).when(mockCSIClient).updateUserAttributes(any(UpdateUserAttributesRequest.class));
    // Store tokens in shared preferences
    SharedPreferences sharedPreferences = appContext.getSharedPreferences("CognitoIdentityProviderCache", Context.MODE_PRIVATE);
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L)).commit();
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(3600L)).commit();
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN).commit();
    CognitoUserAttributes attributes = new CognitoUserAttributes();
    attributes.addAttribute("TestAttribute1", "TestData1");
    attributes.addAttribute("TestAttribute2", "TestData2");
    testUser.updateAttributesInBackground(attributes, new UpdateAttributesHandler() {

        @Override
        public void onSuccess(List<CognitoUserCodeDeliveryDetails> var1) {
            assertNotNull(var1);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : CognitoUserCodeDeliveryDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) UpdateUserAttributesRequest(com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesRequest) UpdateAttributesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler) SharedPreferences(android.content.SharedPreferences) CognitoUserAttributes(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 38 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderUpdateDetailsTest method updateUserAttributeInBackgroundWithCachedTokens.

// Get user attributes - in background
@Test
public void updateUserAttributeInBackgroundWithCachedTokens() {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Set mock result for the change password request API call
    doReturn(TEST_VALID_UPDATE_USER_RESULT).when(mockCSIClient).updateUserAttributes(any(UpdateUserAttributesRequest.class));
    // Store tokens in shared preferences
    SharedPreferences sharedPreferences = appContext.getSharedPreferences("CognitoIdentityProviderCache", Context.MODE_PRIVATE);
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L)).commit();
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(3600L)).commit();
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN).commit();
    CognitoUserAttributes attributes = new CognitoUserAttributes();
    attributes.addAttribute("TestAttribute1", "TestData1");
    attributes.addAttribute("TestAttribute2", "TestData2");
    testUser.updateAttributesInBackground(attributes, new UpdateAttributesHandler() {

        @Override
        public void onSuccess(List<CognitoUserCodeDeliveryDetails> var1) {
            // Extract the arguments passed to get user API call
            ArgumentCaptor<GetUserRequest> argumentCaptor = ArgumentCaptor.forClass(GetUserRequest.class);
            verify(mockCSIClient).getUser(argumentCaptor.capture());
            GetUserRequest requestSent = argumentCaptor.getValue();
            // Verify the arguments passed to the API call
            assertNotNull(requestSent);
            assertNotNull(requestSent.getAccessToken());
            // Verify result
            assertNotNull(var1);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : CognitoUserCodeDeliveryDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ArgumentCaptor(org.mockito.ArgumentCaptor) GetUserRequest(com.amazonaws.services.cognitoidentityprovider.model.GetUserRequest) UpdateUserAttributesRequest(com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesRequest) UpdateAttributesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler) SharedPreferences(android.content.SharedPreferences) CognitoUserAttributes(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 39 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderUpdateDetailsTest method updateUserAttributeInCurrentThreadWithCachedTokens.

// Get user attributes -
@Test
public void updateUserAttributeInCurrentThreadWithCachedTokens() {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Set mock result for the change password request API call
    doReturn(TEST_VALID_UPDATE_USER_RESULT).when(mockCSIClient).updateUserAttributes(any(UpdateUserAttributesRequest.class));
    // Store tokens in shared preferences
    SharedPreferences sharedPreferences = appContext.getSharedPreferences("CognitoIdentityProviderCache", Context.MODE_PRIVATE);
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L)).commit();
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(3600L)).commit();
    sharedPreferences.edit().putString("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN).commit();
    CognitoUserAttributes attributes = new CognitoUserAttributes();
    attributes.addAttribute("TestAttribute1", "TestData1");
    attributes.addAttribute("TestAttribute2", "TestData2");
    testUser.updateAttributes(attributes, new UpdateAttributesHandler() {

        @Override
        public void onSuccess(List<CognitoUserCodeDeliveryDetails> var1) {
            // Extract the arguments passed to get user API call
            ArgumentCaptor<GetUserRequest> argumentCaptor = ArgumentCaptor.forClass(GetUserRequest.class);
            verify(mockCSIClient).getUser(argumentCaptor.capture());
            GetUserRequest requestSent = argumentCaptor.getValue();
            // Verify the arguments passed to the API call
            assertNotNull(requestSent);
            assertNotNull(requestSent.getAccessToken());
            // Verify result
            assertNotNull(var1);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : CognitoUserCodeDeliveryDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) ArgumentCaptor(org.mockito.ArgumentCaptor) GetUserRequest(com.amazonaws.services.cognitoidentityprovider.model.GetUserRequest) UpdateUserAttributesRequest(com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesRequest) UpdateAttributesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler) SharedPreferences(android.content.SharedPreferences) CognitoUserAttributes(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Example 40 with CognitoUserPool

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderUpdateDetailsTest method updateUserAttributeInBackgroundWithNoCachedTokens.

@Test
public void updateUserAttributeInBackgroundWithNoCachedTokens() {
    testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCSIClient);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Set mock result for the change password request API call
    doReturn(TEST_VALID_UPDATE_USER_RESULT).when(mockCSIClient).updateUserAttributes(any(UpdateUserAttributesRequest.class));
    CognitoUserAttributes attributes = new CognitoUserAttributes();
    attributes.addAttribute("TestAttribute1", "TestData1");
    attributes.addAttribute("TestAttribute2", "TestData2");
    testUser.updateAttributesInBackground(attributes, new UpdateAttributesHandler() {

        @Override
        public void onSuccess(List<CognitoUserCodeDeliveryDetails> var1) {
            assertNotNull(var1);
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : CognitoUserCodeDeliveryDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails) CognitoUserPool(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) UpdateUserAttributesRequest(com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesRequest) UpdateAttributesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler) CognitoUserAttributes(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) Test(org.junit.Test)

Aggregations

CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)56 Test (org.junit.Test)41 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)28 ArgumentCaptor (org.mockito.ArgumentCaptor)11 SharedPreferences (android.content.SharedPreferences)9 CognitoUser (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser)9 GetUserRequest (com.amazonaws.services.cognitoidentityprovider.model.GetUserRequest)8 ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)8 CognitoUserAttributes (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes)7 SignUpResult (com.amazonaws.services.cognitoidentityprovider.model.SignUpResult)7 Before (org.junit.Before)7 CognitoUserCodeDeliveryDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails)6 CognitoUserDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserDetails)6 GetDetailsHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler)6 SignUpHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.SignUpHandler)6 UpdateAttributesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler)6 SignUpRequest (com.amazonaws.services.cognitoidentityprovider.model.SignUpRequest)6 UnexpectedLambdaException (com.amazonaws.services.cognitoidentityprovider.model.UnexpectedLambdaException)6 UpdateUserAttributesRequest (com.amazonaws.services.cognitoidentityprovider.model.UpdateUserAttributesRequest)6 ClientConfiguration (com.amazonaws.ClientConfiguration)4