This repository has been archived by the owner. 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

Comments

Projects
None yet
6 participants
@jeetendra-choudhary

jeetendra-choudhary commented May 20, 2016

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

This comment has been minimized.

Contributor

itrestian commented May 20, 2016

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

This comment has been minimized.

samuelsensei commented May 20, 2016

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

This comment has been minimized.

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

@appeality

This comment has been minimized.

appeality commented May 22, 2016

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

This comment has been minimized.

jeetendra-choudhary commented May 22, 2016

Hi @appeality,

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

Best Regards
Jeetendra

@amank12

This comment has been minimized.

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.

@appeality

This comment has been minimized.

appeality commented Dec 11, 2016

@amank12 Are you using Angular 2 cli?

@amank12

This comment has been minimized.

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

This comment has been minimized.

owlstack commented Feb 16, 2017

@appeality Where should I include that file?

@jeetendra-choudhary

This comment has been minimized.

jeetendra-choudhary commented Feb 18, 2017

@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.