I couldn't find any documentation that showed how to do this so I tried my best to figure it out (is this not a common use case)? I've set up my resource to use IAM authentication, set up CORS, etc. Then I deployed it, and downloaded the generated the SDK.
On the client-side I'm using the credentials from AWS.CognitoIdentityCredentials with apigClientFactory.newClient. When I try to post to my resource, I get a 403 error response with no body.
The response headers contain: x-amz-ErrorType: UnrecognizedClientException
Could this error possibly be coming from some other AWS service (do they bubble up like that)? If so, how can I tell which one? What else might be causing the error?
The code I'm using test test client-side looks like this:
function onFacebookLogin(fbtoken) {
// get cognito credentials
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:abcd6789-1234-567a-b123-12ab34cd56ef',
Logins: {'graph.facebook.com': fbtoken}
});
AWS.config.credentials.get(function(err) {
if (err) {return console.error('Credentials error: ', err);}
/* I'm assuming that this is what I use for accessKey and secretKey */
var credentials = AWS.config.credentials;
apigClient = apigClientFactory.newClient({
accessKey: credentials.accessKeyId,
secretKey: credentials.secretAccessKey
});
});
}
Amazon Cognito Identity SDK for JavaScript Your User Pool in Amazon Cognito is a fully managed user directory that can scale to hundreds of millions of users, so you don't have to worry about building, securing, and scaling a solution to handle user management and authentication.
I think what might be happening is you're not setting the sessionToken field with the access key and secret key. Can you try setting it up to look like the below example and see if that works?
var client = apigClientFactory.newClient({ accessKey: ACCESS_KEY, secretKey: SECRET_KEY, sessionToken: SESSION_TOKEN });
This previous question has a bit more detail, if needed.
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