Search in sources :

Example 1 with VerificationHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler in project aws-sdk-android by aws-amplify.

the class CognitoUser method getAttributeVerificationCodeInBackground.

/**
 * Requests code to verify a user attribute, in background.
 * <p>
 * The user attributes that can be verified are those attributes that can be
 * used to communicate with the user, e.g. phone_number and email. The
 * verification code is sent to the medium that is represented by the
 * attribute. Attribute verification is required to enable the attribute to
 * be used an attribute as alias for the user. Aliases attributes can be
 * used in lieu of the userId to authenticate the user. If an attribute was
 * used in the confirm the user after sign-up, then that alias is already
 * verified and does not require re-verification.
 * </p>
 *
 * @param clientMetadata A map of custom key-value pairs that is passed to the lambda function for
 *                       lambda functions triggered by forgot password.
 * @param attributeName REQUIRED: Name of the attribute that requires
 *            verification.
 * @param callback REQUIRED: callback.
 */
public void getAttributeVerificationCodeInBackground(final Map<String, String> clientMetadata, final String attributeName, final VerificationHandler callback) {
    if (callback == null) {
        throw new CognitoParameterInvalidException("callback is null");
    }
    final CognitoUser user = this;
    new Thread(new Runnable() {

        @Override
        public void run() {
            final Handler handler = new Handler(context.getMainLooper());
            Runnable returnCallback;
            try {
                final CognitoUserSession session = user.getCachedSession();
                final GetUserAttributeVerificationCodeResult getUserAttributeVerificationCodeResult = getAttributeVerificationCodeInternal(clientMetadata, attributeName, session);
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        callback.onSuccess(new CognitoUserCodeDeliveryDetails(getUserAttributeVerificationCodeResult.getCodeDeliveryDetails()));
                    }
                };
            } catch (final Exception e) {
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        callback.onFailure(e);
                    }
                };
            }
            handler.post(returnCallback);
        }
    }).start();
}
Also used : CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) GetUserAttributeVerificationCodeResult(com.amazonaws.services.cognitoidentityprovider.model.GetUserAttributeVerificationCodeResult) Handler(android.os.Handler) GetDetailsHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) VerificationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler) UpdateAttributesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler) ForgotPasswordHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler) RegisterMfaHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.RegisterMfaHandler) DevicesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CognitoInternalErrorException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException) UserNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException) CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoNotAuthorizedException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)

Example 2 with VerificationHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler in project aws-sdk-android by aws-amplify.

the class CognitoUser method resendConfirmationCodeInBackground.

/**
 * Request to resend registration confirmation code for a user, in
 * background.
 *
 * @param clientMetadata A map of custom key-value pairs that is passed to the lambda function for
 *                       custom workflow.
 * @param callback REQUIRED: {@link VerificationHandler} callback handler.
 */
public void resendConfirmationCodeInBackground(final Map<String, String> clientMetadata, final VerificationHandler callback) {
    if (callback == null) {
        throw new CognitoParameterInvalidException("callback is null");
    }
    new Thread(new Runnable() {

        @Override
        public void run() {
            final Handler handler = new Handler(context.getMainLooper());
            Runnable returnCallback;
            try {
                final ResendConfirmationCodeResult resendConfirmationCodeResult = resendConfirmationCodeInternal(clientMetadata);
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        callback.onSuccess(new CognitoUserCodeDeliveryDetails(resendConfirmationCodeResult.getCodeDeliveryDetails()));
                    }
                };
            } catch (final Exception e) {
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        callback.onFailure(e);
                    }
                };
            }
            handler.post(returnCallback);
        }
    }).start();
}
Also used : CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) ResendConfirmationCodeResult(com.amazonaws.services.cognitoidentityprovider.model.ResendConfirmationCodeResult) Handler(android.os.Handler) GetDetailsHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) VerificationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler) UpdateAttributesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler) ForgotPasswordHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler) RegisterMfaHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.RegisterMfaHandler) DevicesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CognitoInternalErrorException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException) UserNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException) CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoNotAuthorizedException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)

Example 3 with VerificationHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler in project aws-sdk-android by aws-amplify.

the class CognitoUserPoolsSignInProvider method resendConfirmationCode.

/**
 * Resent the confirmation code on MFA.
 */
private void resendConfirmationCode() {
    final CognitoUser cognitoUser = cognitoUserPool.getUser(username);
    cognitoUser.resendConfirmationCodeInBackground(new VerificationHandler() {

        @Override
        public void onSuccess(final CognitoUserCodeDeliveryDetails verificationCodeDeliveryMedium) {
            startVerificationActivity();
        }

        @Override
        public void onFailure(final Exception exception) {
            if (null != resultsHandler) {
                ViewHelper.showDialog(activity, activity.getString(R.string.title_activity_sign_in), activity.getString(R.string.login_failed) + "\nUser was not verified and resending confirmation code failed.\n" + getErrorMessageFromException(exception));
                resultsHandler.onError(CognitoUserPoolsSignInProvider.this, exception);
            }
        }
    });
}
Also used : CognitoUserCodeDeliveryDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails) VerificationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler) CognitoUser(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) UserNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException) JSONException(org.json.JSONException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) UserNotConfirmedException(com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException)

Example 4 with VerificationHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler in project aws-sdk-android by aws-amplify.

the class CognitoUser method verifyAttributeInBackground.

/**
 * Verify an attribute with the verification code, in background.
 * <p>
 * Call this method to verify an attribute with the "verification code". To
 * request for a "verification code" call the method
 * {@link CognitoUser#getAttributeVerificationCodeInBackground(String, VerificationHandler)}
 * .
 * </p>
 *
 * @param attributeName REQUIRED: The attribute that is being verified.
 * @param verificationCode REQUIRED: The code for verification.
 * @param callback REQUIRED: Callback
 */
public void verifyAttributeInBackground(final String attributeName, final String verificationCode, final GenericHandler callback) {
    if (callback == null) {
        throw new CognitoParameterInvalidException("callback is null");
    }
    final CognitoUser user = this;
    new Thread(new Runnable() {

        @Override
        public void run() {
            final Handler handler = new Handler(context.getMainLooper());
            Runnable returnCallback;
            try {
                final CognitoUserSession session = user.getCachedSession();
                verifyAttributeInternal(attributeName, verificationCode, session);
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        callback.onSuccess();
                    }
                };
            } catch (final Exception e) {
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        callback.onFailure(e);
                    }
                };
            }
            handler.post(returnCallback);
        }
    }).start();
}
Also used : CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) Handler(android.os.Handler) GetDetailsHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) VerificationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler) UpdateAttributesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler) ForgotPasswordHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler) RegisterMfaHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.RegisterMfaHandler) DevicesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CognitoInternalErrorException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException) UserNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException) CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoNotAuthorizedException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)

Aggregations

VerificationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler)4 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)4 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)4 UserNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException)4 Handler (android.os.Handler)3 CognitoInternalErrorException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException)3 CognitoNotAuthorizedException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)3 CognitoParameterInvalidException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException)3 AuthenticationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler)3 DevicesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler)3 ForgotPasswordHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler)3 GenericHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler)3 GetDetailsHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler)3 RegisterMfaHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.RegisterMfaHandler)3 UpdateAttributesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler)3 ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CognitoUser (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser)1 CognitoUserCodeDeliveryDetails (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails)1 GetUserAttributeVerificationCodeResult (com.amazonaws.services.cognitoidentityprovider.model.GetUserAttributeVerificationCodeResult)1