Search in sources :

Example 1 with ForgotPasswordResult

use of com.amazonaws.services.cognitoidentityprovider.model.ForgotPasswordResult 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 ForgotPasswordResult

use of com.amazonaws.services.cognitoidentityprovider.model.ForgotPasswordResult in project aws-sdk-android by aws-amplify.

the class CognitoUser method forgotPassword.

/**
 * Starts the process to set a new new password for forgotten password case,
 * in current thread.
 * <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()}.
 * <b>Note:</b> This method will perform network operations. Calling this
 * method in applications' main thread will cause Android to throw
 * NetworkOnMainThreadException.
 * </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 forgotPassword(final Map<String, String> clientMetadata, final ForgotPasswordHandler callback) {
    if (callback == null) {
        throw new CognitoParameterInvalidException("callback is null");
    }
    final CognitoUser cognitoUser = this;
    try {
        final ForgotPasswordResult forgotPasswordResult = forgotPasswordInternal(clientMetadata);
        final ForgotPasswordContinuation continuation = new ForgotPasswordContinuation(cognitoUser, new CognitoUserCodeDeliveryDetails(forgotPasswordResult.getCodeDeliveryDetails()), ForgotPasswordContinuation.RUN_IN_CURRENT, callback);
        callback.getResetCode(continuation);
    } catch (final Exception e) {
        callback.onFailure(e);
    }
}
Also used : CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) ForgotPasswordContinuation(com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ForgotPasswordContinuation) 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)

Aggregations

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 ForgotPasswordResult (com.amazonaws.services.cognitoidentityprovider.model.ForgotPasswordResult)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 Handler (android.os.Handler)1 AuthenticationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler)1 DevicesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler)1 ForgotPasswordHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler)1 GenericHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler)1 GetDetailsHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler)1 RegisterMfaHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.RegisterMfaHandler)1 UpdateAttributesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler)1 VerificationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler)1