使用AWS Cognito对用户进行身份验证时出错

时间:2016-12-11 15:43:26

标签: amazon-cognito

以下是我正在使用的代码:

<!DOCTYPE html>
<html>
<head>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.6.10.min.js"></script>
<script src="aws-cognito-sdk.min.js"></script>
<script src="amazon-cognito-identity.min.js"></script>
<script src="jsbn.js"></script>
<script src="jsbn2.js"></script>
<script src="sjcl.js"></script>
</head>

<body>

<script>

AWSCognito.config.region = 'ap-northeast-2'; //This is required to derive the endpoint

AWSCognito.config.update({accessKeyId: 'AKIAJMOWHTPNDMXG5OGA', secretAccessKey: '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'})

var poolData = { UserPoolId : 'ap-northeast-2_go0rGKVb5',
    ClientId : '6a0n8dqpi9i7be9mtve36u6klm'
};

var authenticationData = {
    Username : 'username',
    Password : 'Password1#',
};
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);

if ( authenticationDetails != null)
    console.log('Got Authentication');

var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);

if ( userPool != null)
    console.log('Got userPool');



 var userData = {
    Username : 'username',
    Pool : userPool
};
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);

if ( cognitoUser != null)
    console.log('Got cognitoUser');

cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: function (result) {
        console.log('access token + ' + result.getAccessToken().getJwtToken());
        console.log('idToken + ' + result.idToken.jwtToken);
    },

    onFailure: function(err) {
        alert(err);
    },

});

</script>

</body>
</html>

我收到以下错误:

&#34; amazon-cognito-identity.min.js:19Uncaught TypeError:无法读取属性&#39; hex&#39;未定义的(...)&#34;

我使用的sjcl.js包含SDK使用的字节编解码器

2 个答案:

答案 0 :(得分:1)

您是否尝试过切换脚本代码的顺序?您可能想尝试匹配README中给出的顺序。

<script src="/path/to/jsbn.js"></script>
<script src="/path/to/jsbn2.js"></script>
<script src="/path/to/sjcl.js"></script>
<script src="/path/to/aws-cognito-sdk.min.js"></script>
<script src="/path/to/amazon-cognito-identity.min.js"></script>
<script src="/path/to/aws-sdk-2.6.10.js"></script> 

答案 1 :(得分:0)

该程序通过改变上述响应中提到的.js文件的顺序来工作。