Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito AdminGetUser returns undefined object

I am trying to set up an in-page user attribute viewer for site admins, so they can view and set different user variables. When I make the request to my user pool, rather than returning a user object or an HTTP error object, I get the following error:

TypeError: Cannot read property 'byteLength' of undefined
    at Object.isEmptyData (browserHashUtils.js?a069:41)
    at Hmac.update (browserHmac.js?f8e2:34)
    at Object.hmac (util.js?05a3:423)
    at Object.getSigningKey (v4_credentials.js?146b:62)
    at V4.signature (v4.js?2886:98)
    at V4.authorization (v4.js?2886:93)
    at V4.addAuthorization (v4.js?2886:35)
    at eval (event_listeners.js?b7ab:236)
    at finish (config.js?6e76:379)
    at eval (config.js?6e76:397) "TypeError: Cannot read property 'byteLength' of undefined
    at Object.isEmptyData (webpack-internal:///./node_modules/aws-sdk/lib/browserHashUtils.js:41:17)
    at Hmac.update (webpack-internal:///./node_modules/aws-sdk/lib/browserHmac.js:34:19)
    at Object.hmac (webpack-internal:///./node_modules/aws-sdk/lib/util.js:423:50)
    at Object.getSigningKey (webpack-internal:///./node_modules/aws-sdk/lib/signers/v4_credentials.js:62:8)
    at V4.signature (webpack-internal:///./node_modules/aws-sdk/lib/signers/v4.js:98:36)
    at V4.authorization (webpack-internal:///./node_modules/aws-sdk/lib/signers/v4.js:93:36)
    at V4.addAuthorization (webpack-internal:///./node_modules/aws-sdk/lib/signers/v4.js:35:12)
    at eval (webpack-internal:///./node_modules/aws-sdk/lib/event_listeners.js:236:18)
    at finish (webpack-internal:///./node_modules/aws-sdk/lib/config.js:379:7)
    at eval (webpack-internal:///./node_modules/aws-sdk/lib/config.js:397:9)"

Now obviously it is returning a null object. What I want to know is why it is returning null instead of any other error, such as 'UserNotFound' or any other 400 error found here, but instead an empty object. It seems to be something wrong with what I'm passing in, however independent of the params plugged into AdminGetUser, as it is the same whether or not the values are valid, however missing them will throw a 400 error.

My current code is as follows:

import  AWS  from 'aws-sdk'
        AWS.config.region = 'us-west-2'; // Region
        AWS.config.credentials = new AWS.CognitoIdentityCredentials({
            IdentityPoolId: 'us-west-2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        });
        AWS.config.accessKeyId = "xxxxxxxxxxxxxxxxxx"
        AWS.config.secretAccessKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
        var params = {
          Username: 'xxxxxxxxx',
          UserPoolId: 'us-west-xxxxxxxx'
        }
        cognitoidentityserviceprovider.adminGetUser(params, function(err,data){
          if(err) console.log( err, err.stack);
          else    {
            console.log(data)
          };
        });

So far I have:

  • updated the aws-sdk module
  • ensured that access keys and secret access keys were valid by generating new ones and copy+pasting
  • ensured identity pool id, user pool id, and region were accurate
  • tested to try to get ERROR 400: User Not Found by substituting the valid username for an invalid username to the same effect
  • did the same as above with an in/valid user pool id to the same effect
  • tested the command in the AWS CLI as aws cognito-idp --user-pool-id id iiusername validusername and got the proper response

Has anyone come across the same thing, and how did you fix it?

like image 886
awsirkis Avatar asked Dec 10 '25 20:12

awsirkis


1 Answers

The reason was that I was only updating AWS.config, which meant that AWS.config.credentials.accessKeyId and AWS.config.credentials.secretAccessKey were undefined. When the Admin API tried to read these, it threw 'undefined' because there simply wasn't any data. By adding in the exact same values to the above fields as their AWS.config counterparts, I get my data.

async adminGetUser(_, {username}){
        AWS.config.region = 'us-west-2'; // Region
        AWS.config.credentials = new AWS.CognitoIdentityCredentials({
            IdentityPoolId: 'us-west-2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        });
        AWS.config.accessKeyId = "xxxxxxxxxxxxxxxxxxx"
        AWS.config.secretAccessKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        AWS.config.credentials.accessKeyId = "xxxxxxxxxxxxxxxxxx"
        AWS.config.credentials.secretAccessKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        AWS.config.apiVersion = 'latest'
        AWS.config.maxRetries = 100
        var cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
        var params = {
          Username: username,
          UserPoolId: 'us-west-xxxxxxxxx'
        }
        cognitoidentityserviceprovider.adminGetUser(params, function(err,data){
          if(err) console.log( err, err.stack);
          else    {
            console.log(data)
            return data
          };
        });

    },

The function it's called from:

let params = {
            username: this.USERNAME
        }
        console.log("getting user")
        let user = await this.$store.dispatch('adminGetUser', params);
        console.log(user)

And output:

getting user

undefined

{userdata}
like image 92
awsirkis Avatar answered Dec 13 '25 10:12

awsirkis



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!