Hi ,
I am trying to login the user after successful sign up. However I am getting below error -
TypeError: undefined is not an object (evaluating 'sjcl.codec.bytes.toBits')
var signin = {};
signin.login = function(){
signin.userName = $("#loginUserName").val();
signin.userPassword = $("#loginPassword").val();
AWSCognito.config.region = 'us-east-1';
AWSCognito.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: '...' // your identity pool id here
});
// Need to provide placeholder keys unless unauthorised user access is enabled for user pool
AWSCognito.config.update({accessKeyId: 'anything', secretAccessKey: 'anything'})
var authenticationData = {
Username : signin.userName,
Password : signin.userPassword,
};
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
var poolData = {
UserPoolId : APP_CONSTANT.USER_POOL_ID,
ClientId : APP_CONSTANT.CLIENT_ID
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var userData = {
Username : signin.userName,
Pool : userPool
};
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log('access token + ' + result.getAccessToken().getJwtToken());
},
onFailure: function(err) {
alert(err);
},
});
};
`
Here is my repository for the code, Really appreciate any help in this regard.
Thanks & Regards
Jeetendra
Hi Jeetendra,
This happens because the Stanford JavaScript Crypto Library doesn't include the bytes codec that the SDK uses so it must be included with the --with-codecBytes option when configuring the Stanford JavaScript Crypto Library (see sjlc README/INSTALL). It is known to build on Linux and requires a Java runtime.
Ionut.
This might help you out.
https://github.com/aws/amazon-cognito-identity-js/issues/9
One of the comments has a zip file with the bytes codec included in the sjcl. It should do the trick.
Hi @itrestian ,
Thanks for the information and reference, however I am not very sure how to proceed with this issue. I am using local machine to test this and have the java runtime available, but I am not able to configure and use SJCL due to lack of proper documentation regarding this. Is there any more specific documentation on how to utilise it with plain javascript.
@samuelsensei the provided link doesn't work and gives a page not found error.
I have created a question on Stack Overflow for same.
Thanks & Regards
Jeetendra
The link provided by samuelsensei is broken, this should link directly to the zip of the library with the codec included:
https://github.com/aws/amazon-cognito-identity-js/files/233157/sjcl.js.zip
or
Hi @appeality,
Thanks a lot you made my day. Now it works perfectly. Thank you very very much.
Best Regards
Jeetendra
I am getting following error using similar code for authenticating user ;
"amazon-cognito-identity.min.js:19Uncaught TypeError: Cannot read property 'hex' of undefined(…)"
I tried with sjcl.js attached in this thread.
@amank12 Are you using Angular 2 cli?
I am using JavaScript in HTML.
This problem got resolved after I changed order of js files included at top of file.
@appeality Where should I include that file?
@owlstack
You should include below mentioned scripts in your index.html file or which ever file you are loading first.
<!-- Javascript -->
<script src="assets/js/jquery-1.11.1.min.js"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.3.11.min.js"></script>
<script src="assets/js/jsbn.js"></script>
<script src="assets/js/jsbn2.js"></script>
<script src="assets/js/sjcl.js"></script>
<script src="assets/js/moment.js"></script>
<script src="assets/js/aws-cognito-sdk.min.js"></script>
<script src="assets/js/amazon-cognito-identity.min.js"></script>
<script src="assets/js/aws-sdk.min.js"></script>
<script src="https://github.jspm.io/jmcriffey/[email protected]/traceur-runtime.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/systemjs/0.18.4/system.src.js"></script>
<script>
System.config({
defaultJSExtensions: true
});
</script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/js/jquery.backstretch.min.js"></script>
<script src="assets/js/scripts.js"></script>
<script src="assets/js/signup.js"></script>
<script src="assets/js/signin.js"></script>
<script src="assets/js/APP_CONSTANT.js"></script>
<!--[if lt IE 10]>
<script src="assets/js/placeholder.js"></script>
<![endif]-->`