Skip to content
This repository has been archived by the owner on Feb 24, 2018. It is now read-only.

Not able to login the user due to sjcl error #39

Closed
jeetendra-choudhary opened this issue May 20, 2016 · 10 comments
Closed

Not able to login the user due to sjcl error #39

jeetendra-choudhary opened this issue May 20, 2016 · 10 comments

Comments

@jeetendra-choudhary
Copy link

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

@itrestian
Copy link
Contributor

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.

@samuelsensei
Copy link

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.

@jeetendra-choudhary
Copy link
Author

jeetendra-choudhary commented May 21, 2016

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

@AdonousTech
Copy link

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

sjcl.js.zip

@jeetendra-choudhary
Copy link
Author

Hi @appeality,

Thanks a lot you made my day. Now it works perfectly. Thank you very very much.

Best Regards
Jeetendra

@amank12
Copy link

amank12 commented Dec 11, 2016

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.

@AdonousTech
Copy link

@amank12 Are you using Angular 2 cli?

@amank12
Copy link

amank12 commented Dec 12, 2016

I am using JavaScript in HTML.

This problem got resolved after I changed order of js files included at top of file.

@owlstack
Copy link

@appeality Where should I include that file?

@jeetendra-choudhary
Copy link
Author

@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/bower-traceur-runtime@0.0.92/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]-->`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants