2017-09-14 55 views
2

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

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

回答

3

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

+0

请标明答案 – Efren

0

我解决了这个问题,与蟒蛇:

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