2017-09-14 156 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')