use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes 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);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes 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);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes 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);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes 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);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes in project aws-sdk-android by aws-amplify.
the class OAuth2Utils method _signUp.
private Runnable _signUp(final String username, final String password, final Map<String, String> userAttributes, final Map<String, String> validationData, final Map<String, String> clientMetadata, final Callback<SignUpResult> callback) {
return new Runnable() {
@Override
public void run() {
final CognitoUserAttributes cognitoUserAttr = new CognitoUserAttributes();
for (final String key : userAttributes.keySet()) {
cognitoUserAttr.addAttribute(key, userAttributes.get(key));
}
userpool.signUp(username, password, cognitoUserAttr, validationData, clientMetadata, new SignUpHandler() {
@Override
public void onSuccess(final CognitoUser user, final com.amazonaws.services.cognitoidentityprovider.model.SignUpResult signUpResult) {
signUpUser = user;
if (signUpResult == null) {
callback.onError(new Exception("SignUpResult received is null"));
return;
}
// CognitoUserCodeDeliveryDetails only when the user is not confirmed.
if (signUpResult.getCodeDeliveryDetails() == null) {
callback.onResult(new SignUpResult(signUpResult.getUserConfirmed(), null, signUpResult.getUserSub()));
} else {
UserCodeDeliveryDetails userCodeDeliveryDetails = new UserCodeDeliveryDetails(signUpResult.getCodeDeliveryDetails().getDestination(), signUpResult.getCodeDeliveryDetails().getDeliveryMedium(), signUpResult.getCodeDeliveryDetails().getAttributeName());
callback.onResult(new SignUpResult(signUpResult.getUserConfirmed(), userCodeDeliveryDetails, signUpResult.getUserSub()));
}
}
@Override
public void onFailure(Exception exception) {
callback.onError(exception);
}
});
}
};
}
Aggregations