jpvanhal / flask-basicauth

HTTP basic access authentication for Flask.
https://flask-basicauth.readthedocs.io/
Other
85 stars 27 forks source link

flask_basicauth.py: add BASIC_AUTH_ALLOW_OPTIONS override flag #14

Open megahall opened 6 years ago

megahall commented 6 years ago

CORS requires pre-flight OPTIONS method requests to work without the Authorization header from the browser.

Otherwise, the browser will raise CORS errors on calls to any endpoints protected with basic auth, and the requests will not work properly. Here is an example error message from Chrome: Failed to load https://host:port/api_url: Response for preflight has invalid HTTP status code 401.

With the BASIC_AUTH_ALLOW_OPTIONS config option enabled, the OPTIONS requests are allowed, and Flask-CORS can send back the right response for the browser, so that the endpoints will work with CORS enabled.