[英]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.