简体   繁体   English

AWS Cognito Admin创建的用户临时密码验证并重置

[英]AWS Cognito Admin created user temp password verify & reset

我试图验证管理员使用AWS Cognito通过密码重置挑战创建的用户生成的临时密码,但我找不到如何使用临时密码并在javascript中为新用户设置新密码的方式或示例。

The Amazon Cognito developer guide provides an example of authenticating with a temporary password and handling the newPasswordRequired condition: Amazon Cognito开发人员指南提供了一个示例,该示例使用临时密码进行身份验证并处理newPasswordRequired条件:

cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: [...],
    onFailure: [...],
    mfaRequired: [...],
    newPasswordRequired: function(userAttributes, requiredAttributes) {
        // User was signed up by an admin and must provide new 
        // password and required attributes, if any, to complete 
        // authentication.

        // userAttributes: object, which is the user's current profile. It will list all attributes that are associated with the user. 
        // Required attributes according to schema, which don’t have any values yet, will have blank values.
        // requiredAttributes: list of attributes that must be set by the user along with new password to complete the sign-in.


        // Get these details and call 
        // newPassword: password that user has given
        // attributesData: object with key as attribute name and value that the user has given.
        cognitoUser.completeNewPasswordChallenge(newPassword, attributesData, this)
    }
});

Excerpted from the guide here: https://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-identity-user-pools-javascript-example-authenticating-admin-created-user.html 摘录自以下指南: https : //docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-identity-user-pools-javascript-example-authenticating-admin-created-user.html

Note that the third argument to completeNewPasswordChallenge in the example is this , ie, the object with the handler functions. 请注意,示例中completeNewPasswordChallenge的第三个参数是this ,即具有处理函数的对象。 This is because completeNewPasswordChallenge requires onSuccess and onFailure handlers, and you can often use the same handlers as you would for the authenticateUser result. 这是因为completeNewPasswordChallenge需要onSuccessonFailure处理程序,并且您经常可以使用与authenticateUser结果相同的处理程序。

I did go through the document you referred to. 我确实浏览了您提到的文档。 I do not understand what should be ' attributesData '. 我不明白什么是“ attributesData ”。 Below is what I have done till now. 以下是我到目前为止所做的事情。

var authenticationData = {
       Username : email,
       Password : temppassword,
   };
   var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
   cognitoUser.authenticateUser(authenticationDetails, {
       onSuccess: function (result) {
           console.log('access token + ' + result.getAccessToken().getJwtToken());
           console.log('idToken + ' + result.idToken.jwtToken);// User authentication was successful
       },

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

       newPasswordRequired: function(userAttributes, requiredAttributes) {
           userAttributes: authenticationData; 
           requiredAttributes: email;
           var newPassword: password;
           // attributesData: object with key as attribute name and value that the user has given.
           cognitoUser.completeNewPasswordChallenge(newPassword, attributesData, this)
       }
   });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM