use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project amplify-android by aws-amplify.
the class AuthComponentTest method updateUserAttributeWithOptions.
/**
* Tests that updateUserAttribute method of the Auth wrapper of AWSMobileClient (AMC) calls
* AMC.updateUserAttributes with the user attribute and options it received.
* Also ensures that in the onResult case, the success callback receives a valid AuthUpdateAttributeResult and in
* the onError case, the error call back receives an AuthException with the root cause attached.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void updateUserAttributeWithOptions() throws AuthException {
AuthUserAttribute attribute = new AuthUserAttribute(AuthUserAttributeKey.custom(ATTRIBUTE_KEY), ATTRIBUTE_VAL);
Map<String, String> attributeMap = Collections.singletonMap(attribute.getKey().getKeyString(), attribute.getValue());
List<UserCodeDeliveryDetails> userCodeDeliveryDetailsList = Collections.singletonList(new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME));
AWSCognitoAuthUpdateUserAttributeOptions.CognitoBuilder options = AWSCognitoAuthUpdateUserAttributeOptions.builder();
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("key", "value");
options.metadata(metadata);
AWSCognitoAuthUpdateUserAttributeOptions builtOptions = options.build();
doAnswer(invocation -> {
Callback<List<UserCodeDeliveryDetails>> callback = invocation.getArgument(2);
callback.onResult(userCodeDeliveryDetailsList);
return null;
}).when(mobileClient).updateUserAttributes(any(), any(), Mockito.<Callback<List<UserCodeDeliveryDetails>>>any());
AuthUpdateAttributeResult result = synchronousAuth.updateUserAttribute(attribute, builtOptions);
assertTrue(result.isUpdated());
assertEquals(AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE, result.getNextStep().getUpdateAttributeStep());
validateCodeDeliveryDetails(result.getNextStep().getCodeDeliveryDetails());
verify(mobileClient).updateUserAttributes(eq(attributeMap), eq(metadata), Mockito.<Callback<List<UserCodeDeliveryDetails>>>any());
}
use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project amplify-android by aws-amplify.
the class AuthComponentTest method resetPassword.
/**
* Tests that the resetPassword method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.forgotPassword with
* the username it received.
* Also ensures that in the onResult case, the success callback receives a valid AuthResetPasswordResult and in
* the onError case, the error call back receives an AuthException with the root cause attached.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void resetPassword() throws AuthException {
ForgotPasswordResult amcResult = new ForgotPasswordResult(ForgotPasswordState.CONFIRMATION_CODE);
amcResult.setParameters(new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME));
doAnswer(invocation -> {
Callback<ForgotPasswordResult> callback = invocation.getArgument(2);
callback.onResult(amcResult);
return null;
}).when(mobileClient).forgotPassword(any(), any(), Mockito.<Callback<ForgotPasswordResult>>any());
AuthResetPasswordResult result = synchronousAuth.resetPassword(USERNAME);
assertFalse(result.isPasswordReset());
assertEquals(AuthResetPasswordStep.CONFIRM_RESET_PASSWORD_WITH_CODE, result.getNextStep().getResetPasswordStep());
validateCodeDeliveryDetails(result.getNextStep().getCodeDeliveryDetails());
verify(mobileClient).forgotPassword(eq(USERNAME), any(), Mockito.<Callback<ForgotPasswordResult>>any());
}
use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project amplify-android by aws-amplify.
the class AuthComponentTest method resendUserAttributeConfirmationCodeWithOptions.
/**
* Tests the resendUserAttributeConfirmationCode method of the Auth wrapper of AWSMobileClient (AMC) Calls
* AMC.verifyUserAttribute with the user attribute key to be verified and options it received.
* @throws AuthException test fails if this gets thrown since method should succeed
*/
@Test
public void resendUserAttributeConfirmationCodeWithOptions() throws AuthException {
AuthUserAttributeKey attributeKey = AuthUserAttributeKey.custom(ATTRIBUTE_KEY);
UserCodeDeliveryDetails userCodeDeliveryDetails = new UserCodeDeliveryDetails(DESTINATION, DELIVERY_MEDIUM, ATTRIBUTE_NAME);
AWSCognitoAuthResendUserAttributeConfirmationCodeOptions.CognitoBuilder options = AWSCognitoAuthResendUserAttributeConfirmationCodeOptions.builder();
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("key", "value");
options.metadata(metadata);
AWSCognitoAuthResendUserAttributeConfirmationCodeOptions builtOptions = options.build();
doAnswer(invocation -> {
Callback<UserCodeDeliveryDetails> callback = invocation.getArgument(2);
callback.onResult(userCodeDeliveryDetails);
return null;
}).when(mobileClient).verifyUserAttribute(any(), any(), Mockito.<Callback<UserCodeDeliveryDetails>>any());
AuthCodeDeliveryDetails result = synchronousAuth.resendUserAttributeConfirmationCode(attributeKey, builtOptions);
validateCodeDeliveryDetails(result);
verify(mobileClient).verifyUserAttribute(eq(attributeKey.getKeyString()), eq(metadata), Mockito.<Callback<UserCodeDeliveryDetails>>any());
}
use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails 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);
}
});
}
};
}
use of com.amazonaws.mobile.client.results.UserCodeDeliveryDetails in project aws-sdk-android by aws-amplify.
the class OAuth2Utils method _forgotPassword.
private Runnable _forgotPassword(final String username, final Map<String, String> clientMetadata, final Callback<ForgotPasswordResult> callback) {
return new Runnable() {
@Override
public void run() {
forgotPasswordCallback = new InternalCallback<ForgotPasswordResult>(callback);
userpool.getUser(username).forgotPasswordInBackground(clientMetadata, new ForgotPasswordHandler() {
@Override
public void onSuccess() {
forgotPasswordCallback.onResult(new ForgotPasswordResult(ForgotPasswordState.DONE));
}
@Override
public void getResetCode(ForgotPasswordContinuation continuation) {
forgotPasswordContinuation = continuation;
ForgotPasswordResult result = new ForgotPasswordResult(ForgotPasswordState.CONFIRMATION_CODE);
CognitoUserCodeDeliveryDetails parameters = continuation.getParameters();
result.setParameters(new UserCodeDeliveryDetails(parameters.getDestination(), parameters.getDeliveryMedium(), parameters.getAttributeName()));
forgotPasswordCallback.onResult(result);
}
@Override
public void onFailure(Exception exception) {
forgotPasswordCallback.onError(exception);
}
});
}
};
}
Aggregations