2016-06-25 28 views
-1

我在尝试验证用户时遇到了一个奇怪的问题。以下是我的代码。想知道如何通过Cognito用户池对用户进行身份验证时修复相当多的奇怪错误?

//-----Authenticate a user 
    alert('Authenticate a user with application'); 
    var authenticationData = { 
     Username : 'someExistingUserName', 
     Password : 'passwordForExistingUserName', 
    }; 
    var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData); 
    var poolData = { UserPoolId : 'us-east-1_r121212', 
     ClientId : '3g7djfhsdfjkahfjdfhdb1' 
    }; 
    var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData); 
    var userData = { 
     Username : 'someExistingUserName', 
     Pool : userPool 
    }; 
    var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData); 
    alert('hisss2'); 
    cognitoUser.authenticateUser(authenticationDetails, { 
     onSuccess: function (result) { 
      alert('meow'); 
      console.log('access token + ' + result.getAccessToken().getJwtToken()); 
     }, 
     onFailure: function(err) { 
      alert(err); 
     }, 

    }); 

它似乎是在某种意义上工作。

如果我把一个不存在的用户名/密码组合,我得到以下看似正确的错误:

ResourceNotFoundException:用户名/客户ID组合没有找到。

但是,如果我输入了正确的用户名和密码组合,似乎什么也没有发生。没有错误弹出发生(这发生了,当我有一个错误的用户名/密码组合),并且console.log是为了运行onSuccess身份验证不,也没有任何警报弹出我放置在onSuccess处理程序。

它既不触发onSuccess或onFailure,这似乎很奇怪。真奇怪。思考? 我很确定我的设置在使用正确的UserPoolId,ClientId等方面是正确的。这似乎很奇怪。请帮忙,我可以不给你任何回报。

我有一个额外的思想,是Username参数在这里:

var authenticationData = { 
     Username : 'someExistingUserName', 
     Password : 'passwordForExistingUserName', 
    }; 

意思是这里匹配用户名参数:

var userData = { 
      Username : 'someExistingUserName', 
      Pool : userPool 
     }; 

? 我现在做的,但也许他们是两个不同的用户名,我只使用一个或什么? WTF。

+1

删除“美东1_r121212”说,“_”,然后尝试将工作 – error2007s

+0

删除整个“美东1_r121212”或只是“_”? –

+0

只是“_”,它会工作 – error2007s

回答

1

我找到了答案。斯坦福JavaScript加密库不包含SDK使用的字节编解码器。我以为我做到了这一点,但显然不是。我下载了一个已经有字节编解码器的编码器,并且工作完美。该死的。

https://github.com/aws/amazon-cognito-identity-js/issues/39

相关问题