use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes in project aws-sdk-android by aws-amplify.
the class OAuth2Utils method _updateUserAttributes.
private Runnable _updateUserAttributes(final Map<String, String> userAttributes, final Map<String, String> clientMetadata, final Callback<List<UserCodeDeliveryDetails>> callback) {
return new Runnable() {
@Override
public void run() {
if (!waitForSignIn()) {
callback.onError(new Exception("Operation requires a signed-in state"));
return;
}
final CognitoUserAttributes cognitoUserAttributes = new CognitoUserAttributes();
if (userAttributes != null) {
for (final String key : userAttributes.keySet()) {
cognitoUserAttributes.addAttribute(key, userAttributes.get(key));
}
}
userpool.getCurrentUser().updateAttributes(cognitoUserAttributes, clientMetadata, new UpdateAttributesHandler() {
@Override
public void onSuccess(List<CognitoUserCodeDeliveryDetails> attributesVerificationList) {
final List<UserCodeDeliveryDetails> list = new LinkedList<UserCodeDeliveryDetails>();
for (CognitoUserCodeDeliveryDetails details : attributesVerificationList) {
list.add(new UserCodeDeliveryDetails(details.getDestination(), details.getDeliveryMedium(), details.getAttributeName()));
}
callback.onResult(list);
}
@Override
public void onFailure(Exception exception) {
callback.onError(exception);
}
});
}
};
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes in project aws-sdk-android by aws-amplify.
the class SignUpActivity method signUp.
/**
* Retrieve input and return to caller.
* @param view the Android View
*/
public void signUp(final View view) {
final String username = signUpView.getUserName();
final String password = signUpView.getPassword();
final String givenName = signUpView.getGivenName();
final String email = signUpView.getEmail();
final String phone = signUpView.getPhone();
Log.d(LOG_TAG, "username = " + username);
Log.d(LOG_TAG, "given_name = " + givenName);
Log.d(LOG_TAG, "email = " + email);
Log.d(LOG_TAG, "phone = " + phone);
if (username.isEmpty()) {
showError(getString(R.string.sign_up_username_missing));
return;
}
if (password.length() < 6) {
showError(getString(R.string.password_length_validation_failed));
return;
}
final CognitoUserAttributes userAttributes = new CognitoUserAttributes();
userAttributes.addAttribute(GIVEN_NAME, givenName);
userAttributes.addAttribute(EMAIL_ADDRESS, email);
if (!phone.isEmpty()) {
userAttributes.addAttribute(PHONE_NUMBER, phone);
}
final AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(getString(R.string.sign_up_in_progress)).setMessage(getString(R.string.please_wait)).setNeutralButton(android.R.string.ok, null);
final AlertDialog alertDialog = builder.show();
mUserPool.signUpInBackground(username, password, userAttributes, null, new SignUpHandler() {
@Override
public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
alertDialog.dismiss();
final Intent intent = new Intent();
intent.putExtra(USERNAME, username);
intent.putExtra(PASSWORD, password);
intent.putExtra(IS_SIGN_UP_CONFIRMED, signUpResult.getUserConfirmed());
intent.putExtra(CONFIRMATION_DESTINATION, signUpResult.getCodeDeliveryDetails().getDestination());
setResult(RESULT_OK, intent);
finish();
}
@Override
public void onFailure(Exception exception) {
alertDialog.dismiss();
showError(exception.getLocalizedMessage() != null ? getErrorMessageFromException(exception) : "");
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUpdateDetailsTest method updateUserAttributeInCurrentThreadWithNoCachedTokens.
@Test
public void updateUserAttributeInCurrentThreadWithNoCachedTokens() {
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.updateAttributes(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 updateUserAttributeInCurrentThreadWithCachedTokensServiceException.
// Get user attributes -
@Test
public void updateUserAttributeInCurrentThreadWithCachedTokensServiceException() {
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("registration 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.updateAttributes(attributes, new UpdateAttributesHandler() {
@Override
public void onSuccess(List<CognitoUserCodeDeliveryDetails> var1) {
assertNotNull(var1);
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
// System.out.println("Exception: "+exception.toString());
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserAttributes in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderUserPoolTest method init.
@Before
public void init() {
if (firstTime) {
// Initialization
MockitoAnnotations.initMocks(this);
testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET);
awsKeyValueStorageUtility = getAWSKeyValueStorageUtility(testPool);
// Data for tests
TEST_IN_USER_ATTRIBUTES_LIST = new CognitoUserAttributes();
TEST_IN_USER_ATTRIBUTES_LIST.addAttribute("email", TEST_USER_EMAIL);
TEST_IN_USER_ATTRIBUTES_LIST.addAttribute("phone_number", TEST_USER_PHONE);
TEST_IN_VALIDATION_DATA = new HashMap<String, String>();
TEST_IN_VALIDATION_DATA.put("DummyAttribute_1", "Value4DummyAttribute_1");
TEST_IN_VALIDATION_DATA.put("DummyAttribute_2", "Value4DummyAttribute_2");
TEST_IN_VALIDATION_DATA.put("DummyAttribute_3", "Value4DummyAttribute_3");
TEST_REGISTER_USER_RESPONSE = new SignUpResult();
TEST_REGISTER_USER_RESPONSE.setUserConfirmed(true);
TEST_REGISTER_USER_RESPONSE.setCodeDeliveryDetails(TEST_CODE_DELIVERY_DETAIL);
firstTime = false;
}
}
Aggregations