In flask, I\'m using the following snippet to enable HTTP auth:
def authenticate():
return Response(\'\', 401
Custom error responses are really quite easy in Flask. Create a function whose only argument is the HTTP error status code, make it return a flask.Response instance, and decorate it with @app.errorhandler.
@app.errorhandler(401)
def custom_401(error):
return Response('', 401, {'WWW-Authenticate':'Basic realm="Login Required"'})
You can then use abort(401)
to your heart's content.