最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AWS Cognito: How should I handle PasswordResetRequiredException - Stack Overflow

programmeradmin4浏览0评论

I have clicked "Reset Password" in Cognito and now when I login I get "PasswordResetRequiredException", how should I handle this? I cant find anything in the docs that tell me what should I do?

I have clicked "Reset Password" in Cognito and now when I login I get "PasswordResetRequiredException", how should I handle this? I cant find anything in the docs that tell me what should I do?

Share Improve this question asked Apr 29, 2017 at 8:52 Jiew MengJiew Meng 88.3k192 gold badges523 silver badges832 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

check this http://docs.aws.amazon./cognito/latest/developerguide/cognito-user-pools-using-import-tool-password-reset.html

you need to call ForgotPassword()...

I figured out the exact way that you can handle this on (onFailure) callback:

// Create a cognito user instance
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
// Trigger to authenticate the user
cognitoUser.authenticateUser(authenticationDetails, { 
  onFailure: function(err) {
    if (err.code == "PasswordResetRequiredException") {
      // Confirm user data
      cognitoUser.confirmPassword(
        "", // Put your verification code here
        "", // Here is your new password
        {
          onSuccess: result => {
            // Everything worked as expected
          },
          onFailure: err => {
            // Trigger failure
          }
        }
      );
    } else {
      // Trigger failure
    }
  }
});

I think that the specific user should have had an email or sms sent to them (if their email or phone number had been verified). In this email there should be a code which you can use with ConfirmForgotPassword

You would have to implement the newPasswordRequired callback for authenticateUser such as below:

cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: function (result) {
        // User authentication was successful
    },

    onFailure: function(err) {
        // User authentication was not successful
    },

    mfaRequired: function(codeDeliveryDetails) {
        // MFA is required to plete user authentication.
        // Get the code from user and call
        cognitoUser.sendMFACode(mfaCode, this)
    },

    newPasswordRequired: function(userAttributes, requiredAttributes) {
        // User was signed up by an admin and must provide new
        // password and required attributes, if any, to plete
        // authentication.

        // the api doesn't accept this field back
        delete userAttributes.email_verified;

        // Get these details and call
        cognitoUser.pleteNewPasswordChallenge(newPassword, userAttributes, this);
    }
});
发布评论

评论列表(0)

  1. 暂无评论