Skip to content

Add Authorization header when CORS flag is set#1467

Closed
jameslittle230 wants to merge 2 commits intosimonw:mainfrom
jameslittle230:patch-1
Closed

Add Authorization header when CORS flag is set#1467
jameslittle230 wants to merge 2 commits intosimonw:mainfrom
jameslittle230:patch-1

Conversation

@jameslittle230
Copy link

This PR adds the Access-Control-Allow-Headers flag when CORS mode is enabled.

This would fix simonw/datasette-auth-tokens#4. When making cross-origin requests, the server must respond with all allowable HTTP headers. A Datasette instance using auth tokens must accept the Authorization HTTP header in order for cross-origin authenticated requests to take place.

Please let me know if there's a better way of doing this! I couldn't figure out a way to change the app's response from the plugin itself, so I'm starting here. If you'd rather this logic live in the plugin, I'd love any guidance you're able to give.

@simonw
Copy link
Owner

simonw commented Oct 14, 2021

This looks like a good fix to me.

@simonw
Copy link
Owner

simonw commented Oct 14, 2021

The test there failed because it turns out there's a whole bunch of places that set the Access-Control-Allow-Origin header. I'm going to close this PR and ship a fix that refactors those places to use the same code.

@simonw simonw closed this Oct 14, 2021
simonw added a commit that referenced this pull request Oct 14, 2021
simonw added a commit that referenced this pull request Oct 14, 2021
@jameslittle230
Copy link
Author

Yay! Thank you @simonw!!

simonw added a commit that referenced this pull request Oct 24, 2021
simonw added a commit that referenced this pull request Oct 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running Datasette with --cors doesn't allow Authorization header to be passed in

2 participants