1
votes

I'm Using AWS API with Cognito Security authentication in web app.when i call my api without overwriting integration request body mapping template it's working fine.but when i put below few lines in integration request body mapping template like below

    #set($inputRoot = $input.path('$'))
{
 'UserId' :'$context.authorizer.claims.email',
 'Name' :'$context.authorizer.claims.name',
 'UniqueID' :'$context.authorizer.claims.sub'
}

…it gives me below error:

XMLHttpRequest cannot load https://ei25XXXXXXg.execute-api.us-east-2.amazonaws.com/Development/userlogin/getcurrentuser. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:7080' is therefore not allowed access. The response had HTTP status code 400.

but i already enable 'Access-Control-Allow-Origin' to '*' already. does anybody has any idea..?

1

1 Answers

1
votes

“The response had HTTP status code 400” in the message cited in the question indicates the server concluded something’s wrong with the request and is refusing to respond to it as expected.

So you probably want to:

  • doublecheck the request to make sure you didn’t make any syntax errors or whatever
  • test the same request from some other non-browser client/tool (such as curl or postman)
  • check your server logs on the server side to see what messages the server is logging there to indicate what was wrong with the request

The fact that you’re getting a message in your browser console saying “No 'Access-Control-Allow-Origin' header is present on the requested resource” is just incidental—the real problem is that you’re not getting a 200 OK response to begin with but instead getting that 400.

The thing is, most servers, even when configured to send the right CORS headers in responses, typically only send those headers for success responses but not for error responses such as a 400.