2016-12-11 53 views
0

這裏用戶是我使用的代碼:收到一個錯誤,同時驗證使用AWS 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> 

我收到以下錯誤:

「亞馬遜cognito-identity.min.js:19Uncaught類型錯誤:無法讀取的未定義的屬性「十六進制」(......)」

我使用sjcl.js包括該SDK使用的字節編碼解碼器

+0

通過在包含AWS文件之前移動以下文件,可以解決此問題: –

回答

1

你試過切換SC的順序ript標籤?您可能想要嘗試與自述文件中給出的順序相匹配。

<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> 
+0

是的,它通過更改.js文件的順序進行工作。 –

0

該程序通過改變.js文件的順序來工作,如上述響應中所述。