我正在尝试验证管理员通过密码重置挑战创建用户使用AWS Cognito生成的临时密码,我找不到如何使用临时密码和设置新密码的方法或示例对于javascript中的新用户。
答案 0 :(得分:1)
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)
}
});
请注意,示例中completeNewPasswordChallenge
的第三个参数是this
,即具有处理函数的对象。这是因为completeNewPasswordChallenge
需要onSuccess
和onFailure
处理程序,并且您通常可以使用与authenticateUser
结果相同的处理程序。
答案 1 :(得分:0)
我确实浏览了你提到的文件。我不明白应该是什么'attributesData
'。以下是我到目前为止所做的事情。
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)
}
});