use of com.amplifyframework.auth.AuthUserAttribute in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testUpdateUserAttribute.
/**
* Tests that a successful request to update a user attribute will propagate a completion
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testUpdateUserAttribute() throws InterruptedException {
// Arrange an invocation of the success Action
AuthUserAttribute attribute = new AuthUserAttribute(AuthUserAttributeKey.custom(ATTRIBUTE_KEY), ATTRIBUTE_VAL);
AuthUpdateAttributeResult expected = new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.DONE, Collections.emptyMap(), null));
doAnswer(invocation -> {
Consumer<AuthUpdateAttributeResult> onCompletion = invocation.getArgument(1);
onCompletion.accept(expected);
return null;
}).when(delegate).updateUserAttribute(any(), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<AuthUpdateAttributeResult> observer = auth.updateUserAttribute(attribute).test();
// Assert: Completable completes with success
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(expected);
}
use of com.amplifyframework.auth.AuthUserAttribute in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testFetchUserAttributes.
/**
* Tests that a successful request to fetch user attributes will propagate a completion
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testFetchUserAttributes() throws InterruptedException {
// Arrange an invocation of the success Action
List<AuthUserAttribute> expected = Collections.singletonList(new AuthUserAttribute(AuthUserAttributeKey.custom(ATTRIBUTE_KEY), ATTRIBUTE_VAL));
doAnswer(invocation -> {
// 0 = onComplete, 1 = onFailure
Consumer<List<AuthUserAttribute>> onCompletion = invocation.getArgument(0);
onCompletion.accept(expected);
return null;
}).when(delegate).fetchUserAttributes(anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<List<AuthUserAttribute>> observer = auth.fetchUserAttributes().test();
// Assert: Completable completes with success
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(expected);
}
use of com.amplifyframework.auth.AuthUserAttribute in project amplify-android by aws-amplify.
the class RxAuthBindingTest method testUpdateUserAttributes.
/**
* Tests that a successful request to update user attributes will propagate a completion
* back through the binding.
* @throws InterruptedException If test observer is interrupted while awaiting terminal event
*/
@Test
public void testUpdateUserAttributes() throws InterruptedException {
// Arrange an invocation of the success Action
List<AuthUserAttribute> attributes = new ArrayList<>();
AuthUserAttributeKey attributeKey = AuthUserAttributeKey.custom(ATTRIBUTE_KEY);
AuthUserAttributeKey attributeKeyWithoutCode = AuthUserAttributeKey.custom(ATTRIBUTE_KEY_WITHOUT_CODE_DELIVERY);
attributes.add(new AuthUserAttribute(attributeKey, ATTRIBUTE_VAL));
attributes.add(new AuthUserAttribute(attributeKeyWithoutCode, ATTRIBUTE_VAL_WITHOUT_CODE_DELIVERY));
Map<AuthUserAttributeKey, AuthUpdateAttributeResult> attributeResultMap = new HashMap<>();
attributeResultMap.put(attributeKey, new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE, Collections.emptyMap(), new AuthCodeDeliveryDetails(DESTINATION, DeliveryMedium.EMAIL, ATTRIBUTE_NAME))));
attributeResultMap.put(attributeKeyWithoutCode, new AuthUpdateAttributeResult(true, new AuthNextUpdateAttributeStep(AuthUpdateAttributeStep.DONE, Collections.emptyMap(), null)));
doAnswer(invocation -> {
Consumer<Map<AuthUserAttributeKey, AuthUpdateAttributeResult>> onCompletion = invocation.getArgument(1);
onCompletion.accept(attributeResultMap);
return null;
}).when(delegate).updateUserAttributes(any(), anyConsumer(), anyConsumer());
// Act: call the binding
TestObserver<Map<AuthUserAttributeKey, AuthUpdateAttributeResult>> observer = auth.updateUserAttributes(attributes).test();
// Assert: Completable completes with success
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertNoErrors().assertValue(attributeResultMap);
}
use of com.amplifyframework.auth.AuthUserAttribute in project amplify-android by aws-amplify.
the class AWSCognitoAuthPlugin method confirmSignIn.
@Override
public void confirmSignIn(@NonNull String confirmationCode, @NonNull AuthConfirmSignInOptions options, @NonNull Consumer<AuthSignInResult> onSuccess, @NonNull Consumer<AuthException> onException) {
final Map<String, String> metadata = new HashMap<>();
final Map<String, String> userAttributes = new HashMap<>();
if (options instanceof AWSCognitoAuthConfirmSignInOptions) {
metadata.putAll(((AWSCognitoAuthConfirmSignInOptions) options).getMetadata());
for (AuthUserAttribute attribute : ((AWSCognitoAuthConfirmSignInOptions) options).getUserAttributes()) {
userAttributes.put(attribute.getKey().getKeyString(), attribute.getValue());
}
}
awsMobileClient.confirmSignIn(confirmationCode, metadata, userAttributes, new Callback<SignInResult>() {
@Override
public void onResult(SignInResult result) {
try {
AuthSignInResult newResult = convertSignInResult(result);
fetchAndSetUserId(() -> onSuccess.accept(newResult));
} catch (AuthException exception) {
onException.accept(exception);
}
}
@Override
public void onError(Exception error) {
onException.accept(CognitoAuthExceptionConverter.lookup(error, "Confirm sign in failed"));
}
});
}
use of com.amplifyframework.auth.AuthUserAttribute in project amplify-android by aws-amplify.
the class AWSCognitoAuthPlugin method signUp.
@Override
public void signUp(@NonNull String username, @NonNull String password, @NonNull AuthSignUpOptions options, @NonNull final Consumer<AuthSignUpResult> onSuccess, @NonNull final Consumer<AuthException> onException) {
Map<String, String> userAttributes = new HashMap<>();
Map<String, String> validationData = new HashMap<>();
Map<String, String> clientMetadata = new HashMap<>();
if (options.getUserAttributes() != null) {
for (AuthUserAttribute attribute : options.getUserAttributes()) {
userAttributes.put(attribute.getKey().getKeyString(), attribute.getValue());
}
}
if (options instanceof AWSCognitoAuthSignUpOptions) {
validationData = ((AWSCognitoAuthSignUpOptions) options).getValidationData();
clientMetadata = ((AWSCognitoAuthSignUpOptions) options).getClientMetadata();
}
awsMobileClient.signUp(username, password, userAttributes, validationData, clientMetadata, new Callback<SignUpResult>() {
@Override
public void onResult(SignUpResult result) {
onSuccess.accept(convertSignUpResult(result, username));
}
@Override
public void onError(Exception error) {
onException.accept(CognitoAuthExceptionConverter.lookup(error, "Sign up failed"));
}
});
}
Aggregations