-1

I am having an odd problem when trying to authenticate my users. Below is my code.

//-----Authenticate a user
    alert('Authenticate a user with application');
    var authenticationData = {
        Username : 'someExistingUserName',
        Password : 'passwordForExistingUserName',
    };
    var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
    var poolData = { UserPoolId : 'us-east-1_r121212',
        ClientId : '3g7djfhsdfjkahfjdfhdb1'
    };
    var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
    var userData = {
        Username : 'someExistingUserName',
        Pool : userPool
    };
    var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
    alert('hisss2');
    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function (result) {
          alert('meow');
            console.log('access token + ' + result.getAccessToken().getJwtToken());
        },
        onFailure: function(err) {
            alert(err);
        },

    });

It seems to be working in a sense.

If I put in a non existent username/password combination I get the following seemingly correct error:

ResourceNotFoundException: Username/client id combination not found.

If, however, I put in a correct user name and password combination, nothing seems to happen. No error pop up occurs(which was happening when i had a wrong username/password combo), and the console.log that is meant to run onSuccess of authentication does not, nor does any alert pop up I place inside the onSuccess handler.

It is neither triggering onSuccess or onFailure, which just seems weird. Really weird. Thoughts? I'm pretty sure my set up is correct in terms of using the correct UserPoolId, ClientId etc. This seems quite odd. Please help, I can offer you nothing in return.

I had an additional thought, is the Username parameter here:

var authenticationData = {
        Username : 'someExistingUserName',
        Password : 'passwordForExistingUserName',
    };

Meant to be matching the Username parameter here:

var userData = {
            Username : 'someExistingUserName',
            Pool : userPool
        };

? Mine currently do, but perhaps they are two different usernames and I'm only using one or something? WTF.

Mark Keane
  • 984
  • 2
  • 11
  • 26
  • 1
    Remove "us-east-1_r121212" that "_" and then try it will work – Piyush Patil Jun 25 '16 at 00:13
  • Remove the whole "us-east-1_r121212" OR just the "_"? – Mark Keane Jun 25 '16 at 00:14
  • Just "_" and it will work – Piyush Patil Jun 25 '16 at 00:15
  • I tried and it didn't fix the problem :( by the way, "us-east-1_r121212" is not my actual UserPoolId, i just didn't want to post the real one here - but i am almost positive i am using the correct UserPoolId as it worked to register a user, which i have done successfully. – Mark Keane Jun 25 '16 at 00:17
  • Well it becomes difficult to get what is wrong if there is no any error :) – Piyush Patil Jun 25 '16 at 00:19
  • I will try to recreate this today night and see how it goes for me. – Piyush Patil Jun 25 '16 at 01:20
  • That would be awesome – Mark Keane Jun 25 '16 at 01:32
  • I found in the documentation that you need 'To authenticate with Amazon Cognito Identity, the client app needs to generate a random number as part of the Secure Remote Password (SRP) protocol.' I tried this but it didn't solve the problem. 10 hours on this problem :'( – Mark Keane Jun 25 '16 at 03:47
  • I found a clue. The cognitoUser.authenticateUser line that isn't working causes the following error to appear in the console: TypeError: undefined is not an object (evaluating 'sjcl.codec.bytes.toBits'). Thoughts? – Mark Keane Jun 25 '16 at 03:52

1 Answers1

1

I found the answer. The Stanford JavaScript Crypto Library doesn't include the bytes codec that the SDK uses. I thought i had done this but apparently not. I downloaded one that had the bytes codec in it already and it worked perfectly. damn.

https://github.com/aws/amazon-cognito-identity-js/issues/39

Mark Keane
  • 984
  • 2
  • 11
  • 26