Search in sources :

Example 1 with ForgotPasswordHandler

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

the class CognitoUser method forgotPasswordInBackground.

/**
 * Starts the process to set a new password for forgotten password case, in
 * background.
 * <p>
 * This will initiate the process to set a new password when the current
 * password is forgotten. The new password will be successfully set only
 * after the verification code, sent to the registered email or phone number
 * of the user, successfully verified by Cognito Identity Provider service.
 * This method will pass a continuation object to the callback. Use setters
 * in the Continuation object {@link ForgotPasswordContinuation} to set the
 * new password and verification code and call continue on the continuation
 * object, {@code CognitoIdentityProviderContinuation.continueTask()}.
 * </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 callback REQUIRED: {@link ForgotPasswordHandler} callback
 */
public void forgotPasswordInBackground(final Map<String, String> clientMetadata, final ForgotPasswordHandler callback) {
    if (callback == null) {
        throw new CognitoParameterInvalidException("callback is null");
    }
    final CognitoUser cognitoUser = this;
    new Thread(new Runnable() {

        @Override
        public void run() {
            final Handler handler = new Handler(context.getMainLooper());
            Runnable returnCallback;
            try {
                final ForgotPasswordResult forgotPasswordResult = forgotPasswordInternal(clientMetadata);
                final ForgotPasswordContinuation continuation = new ForgotPasswordContinuation(cognitoUser, new CognitoUserCodeDeliveryDetails(forgotPasswordResult.getCodeDeliveryDetails()), ForgotPasswordContinuation.RUN_IN_BACKGROUND, callback);
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        callback.getResetCode(continuation);
                    }
                };
            } 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) ForgotPasswordContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ForgotPasswordContinuation) 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) ForgotPasswordResult(com.amazonaws.services.cognitoidentityprovider.model.ForgotPasswordResult) 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 ForgotPasswordHandler

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

the class CognitoUser method confirmPasswordInBackground.

/**
 * Set new password and send verification code to Cognito Identity Provider
 * service, in background.
 * <p>
 * This method will be called by {@link ForgotPasswordContinuation}
 * continuation object.
 * </p>
 *
 * @param verificationCode REQUIRED: Code sent from Cognito Identity
 *            Provider Service.
 * @param newPassword REQUIRED: New password. On successful verification of
 *            {@code verificationCode}, this will be the new password for
 *            this user.
 * @param clientMetadata A map of custom key-value pairs that you can provide as input for any
 *                       custom workflows triggered by confirm password.
 * @param callback REQUIRED: {@link ForgotPasswordHandler} callback.
 */
public void confirmPasswordInBackground(final String verificationCode, final String newPassword, final Map<String, String> clientMetadata, final ForgotPasswordHandler 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 {
                confirmPasswordInternal(verificationCode, newPassword, clientMetadata);
                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)

Example 3 with ForgotPasswordHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler 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);
                }
            });
        }
    };
}
Also used : CognitoUserCodeDeliveryDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails) ForgotPasswordHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler) ReturningRunnable(com.amazonaws.mobile.client.internal.ReturningRunnable) ForgotPasswordContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ForgotPasswordContinuation) CognitoUserCodeDeliveryDetails(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserCodeDeliveryDetails) UserCodeDeliveryDetails(com.amazonaws.mobile.client.results.UserCodeDeliveryDetails) ForgotPasswordResult(com.amazonaws.mobile.client.results.ForgotPasswordResult) JSONException(org.json.JSONException) InvalidUserPoolConfigurationException(com.amazonaws.services.cognitoidentityprovider.model.InvalidUserPoolConfigurationException) AmazonClientException(com.amazonaws.AmazonClientException) NotAuthorizedException(com.amazonaws.services.cognitoidentity.model.NotAuthorizedException)

Aggregations

ForgotPasswordHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler)3 Handler (android.os.Handler)2 ForgotPasswordContinuation (com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ForgotPasswordContinuation)2 CognitoInternalErrorException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException)2 CognitoNotAuthorizedException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)2 CognitoParameterInvalidException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException)2 AuthenticationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler)2 DevicesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler)2 GenericHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler)2 GetDetailsHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler)2 RegisterMfaHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.RegisterMfaHandler)2 UpdateAttributesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler)2 VerificationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler)2 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)2 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)2 ResourceNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException)2 UserNotFoundException (com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 AmazonClientException (com.amazonaws.AmazonClientException)1 ReturningRunnable (com.amazonaws.mobile.client.internal.ReturningRunnable)1