[英]AWS Cognito Admin created user temp password verify & reset
我试图验证管理员使用AWS Cognito通过密码重置挑战创建的用户生成的临时密码,但我找不到如何使用临时密码并在javascript中为新用户设置新密码的方式或示例。
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)
}
});
摘录自以下指南: https : //docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-identity-user-pools-javascript-example-authenticating-admin-created-user.html
请注意,示例中completeNewPasswordChallenge
的第三个参数是this
,即具有处理函数的对象。 这是因为completeNewPasswordChallenge
需要onSuccess
和onFailure
处理程序,并且您经常可以使用与authenticateUser
结果相同的处理程序。
我确实浏览了您提到的文档。 我不明白什么是“ 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)
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.