我创建了一个AWS cognito用户池,其中包含电子邮件作为必需属性和已检查的电子邮件以进行验证。使用AWSCognitoClient sdk从我的java spring后端服务创建用户并调用adminCreateUser(createUser)方法。用户收到一封包含临时密码的电子邮件,首次登录时会设置新密码。现在当我执行忘记密码流时,我收到以下错误,
InvalidParameterException: Cannot reset password for the user as there is no registered/verified email or phone_number
虽然我已经收到了我注册的电子邮件ID的临时密码并且第一次更改了我的密码但是我收到了上述错误。有人可以解释我错过了什么吗?
以下是我为忘记密码流执行的javascript代码,
forgotPassword(username: String, poolInfo:any){
var poolData = {
UserPoolId : poolInfo.poolId, // Your user pool id here
ClientId : poolInfo.portalClientId // Your client id here
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var userData = {
Username : username,
Pool : userPool
};
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.forgotPassword({
onSuccess: function (result) {
this.router.navigate(['login']);
},
onFailure: function(err) {
alert(err);
},
//Optional automatic callback
inputVerificationCode: function(data) {
var verificationCode = prompt('Please input verification code ' ,'');
var newPassword = prompt('Enter new password ' ,'');
cognitoUser.confirmPassword(verificationCode, newPassword, this);
}
});
}
答案 0 :(得分:3)
解决。我不得不添加" email_verified":" True"作为我从后端服务创建的用户的属性。
答案 1 :(得分:0)
我用python解决了这个问题:
response = cognito_client.get_user_attribute_verification_code(AccessToken='eyJraWQiOiJtTEM4Vm......',AttributeName='email')
response = cognito_client.verify_user_attribute( AccessToken='eyJraWQiOiJtTEM......', AttributeName='email', Code='230433')
def forgot_password(usename):
ClientId = 'f2va............'
response = cognito_client.forgot_password( ClientId=ClientId, Username=username)
def confirm_forgot_password():
ClientId = 'f2va............'
response = cognito_client.confirm_forgot_password(ClientId=ClientId,Username=username,ConfirmationCode='644603',Password='12345678')