use of com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendUserAttributeConfirmationCodeOptions in project amplify-android by aws-amplify.
the class AWSCognitoAuthPlugin method resendUserAttributeConfirmationCode.
@Override
public void resendUserAttributeConfirmationCode(@NonNull AuthUserAttributeKey attributeKey, @NonNull AuthResendUserAttributeConfirmationCodeOptions options, @NonNull Consumer<AuthCodeDeliveryDetails> onSuccess, @NonNull Consumer<AuthException> onError) {
final Map<String, String> clientMetadata = new HashMap<>();
if (options instanceof AWSCognitoAuthResendUserAttributeConfirmationCodeOptions) {
AWSCognitoAuthResendUserAttributeConfirmationCodeOptions cognitoOptions = (AWSCognitoAuthResendUserAttributeConfirmationCodeOptions) options;
clientMetadata.putAll(cognitoOptions.getMetadata());
}
String attributeName = attributeKey.getKeyString();
awsMobileClient.verifyUserAttribute(attributeName, clientMetadata, new Callback<UserCodeDeliveryDetails>() {
@Override
public void onResult(UserCodeDeliveryDetails result) {
onSuccess.accept(convertCodeDeliveryDetails(result));
}
@Override
public void onError(Exception error) {
onError.accept(new AuthException("Failed to resend user attribute confirmation code", error, "See attached exception for more details"));
}
});
}
use of com.amplifyframework.auth.cognito.options.AWSCognitoAuthResendUserAttributeConfirmationCodeOptions 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());
}
Aggregations