serverless-application-model icon indicating copy to clipboard operation
serverless-application-model copied to clipboard

Global CORS AllowCredentials: true not setting header

Open james-burke-codes opened this issue 7 years ago • 4 comments

Description:

I'm getting the following error even though I have applied the AllowCredentials: "true" setting to my config:

Access to XMLHttpRequest at 'http://localhost:3000/auth/token' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

Steps to reproduce the issue:

Globals:
  Api:
    Cors:
      AllowOrigin: "http://localhost:8080"
      AllowHeaders: "*"
      AllowCredentials: "true"

Observed result:

Changing AllowHeaders is reflected in the response to my request.

image

image

Expected result:

No CORS Error :-D

james-burke-codes avatar Sep 29 '19 21:09 james-burke-codes

@peregrinius Could you try by removing the quotes for AllowCredentials: true. AllowCredentials expects a boolean value

Template:

Globals:
  Api:
    Cors:
      AllowOrigin: "http://localhost:8080"
      AllowHeaders: "*"
      AllowCredentials: true

ShreyaGangishetty avatar Oct 01 '19 17:10 ShreyaGangishetty

Thanks for your reply Shreya. I tried that but still the same error :-(

james-burke-codes avatar Oct 02 '19 06:10 james-burke-codes

Hi @peregrinius! It also looks like Cors expects quoted strings:

Globals:
  Api:
    Cors:
      AllowOrigin: "'http://localhost:8080'"
      AllowHeaders: "'*'"
      AllowCredentials: true

https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#cors-configuration

keetonian avatar Oct 04 '19 17:10 keetonian

Hi @keetonian I think the documentation is out of date. They recently released an update to remove the need for putting both single and double quotes.

I removed the { withCredentials: true } from my axios request and it works now 🤷‍♂

james-burke-codes avatar Oct 06 '19 11:10 james-burke-codes