Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito Identity NotAuthorizedException

I'm using the AWS javascript sdk in order to integrate user pools with a web app that I am building. The user pool is setup and I've followed the usage example here: https://github.com/aws/amazon-cognito-identity-js

I keep getting an error that says: "NotAuthorizedException: Unable to verify secret hash for client (my app client id)"

AWS.config.region = 'us-east-1'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: '...' // my identity pool id here
});


AWSCognito.config.region = 'us-east-1';
AWSCognito.config.credentials = new AWS.CognitoIdentityCredentials({
  IdentityPoolId: '...' // my identity pool id here
})


var poolData = {
  UserPoolId: '...', // my user pool id here
  ClientId: '...'  // client id here
};
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);

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

      var attributeList = [];

      var dataEmail = {
          Name : 'email',
          Value : '[email protected]'
      };
      var dataPhoneNumber = {
          Name : 'phone_number',
          Value : '+15555555555'
      };
      var attributeEmail = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataEmail);
      var attributePhoneNumber = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserAttribute(dataPhoneNumber);

      attributeList.push(attributeEmail);
      attributeList.push(attributePhoneNumber);

      userPool.signUp('username', 'password', attributeList, null, function(err, result){
          if (err) {
              alert(err);
              return;
          }
          cognitoUser = result.user;
          console.log('user name is ' + cognitoUser.getUsername());
      });

Any suggestions or potential issues with the code snippet above? Thanks!

like image 674
user3567080 Avatar asked Dec 22 '25 19:12

user3567080


2 Answers

The solution to this is actually quite straightforward. You have to delete the app in aws and re-add it without a secret key so it can authorize.

like image 183
user3567080 Avatar answered Dec 24 '25 08:12

user3567080


When creating a web application using the Javascript SDK you cannot use a secret key as there is no where to store it. This will cause the exception you are seeing.

As you discovered, creating an app without a secret key solves the issue.

like image 37
Mark Mercurio Avatar answered Dec 24 '25 08:12

Mark Mercurio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!