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:
aws-sdk moduleaws cognito-idp --user-pool-id id iiusername validusername and got the proper responseHas anyone come across the same thing, and how did you fix it?
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With