AWS cognito 忘记密码流程

AWS cognito forgot password flow

我创建了一个 AWS cognito 用户池,并将电子邮件作为必需属性并检查了电子邮件以进行验证。用户是使用 AWSCognitoClient sdk 并调用 adminCreateUser(createUser) 方法从我的 java spring 后端服务创建的。用户会收到一封带有临时密码的电子邮件,首次登录时会设置新密码。现在,当我执行忘记密码流程时,出现以下错误,

 InvalidParameterException: Cannot reset password for the user as there is no registered/verified email or phone_number

虽然我已经收到了我注册的电子邮件 ID 的临时密码并更改了我的密码,但我还是第一次收到上述错误。有人可以解释我错过了什么吗?

下面是java正在为忘记密码流程执行的脚本代码,

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);
            }
        });
    }

已解决。我必须添加 "email_verified":"True" 作为我从后端服务创建的用户的属性。

我用 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')

这是官方文档。 https://boto3.amazonaws.com/v1/documentation/api/1.9.42/reference/services/cognito-idp.html#CognitoIdentityProvider.Client.confirm_forgot_password