flask-restx
flask-restx copied to clipboard
Basic Auth for Swagger UI
Any suggestions on how to password protect the swagger UI with basic auth? I was going to use something like flask-httpauth or maybe just write my own wrapper but the Swagger UI route isn't exposed in an obvious way. If you wondering why, I may have to have my API available publicly and don't want anyone who isn't supposed to know the api have any more available information on it but it could be useful for some users. I may restrict it by IP but I'm on unsure of this yet.
You can totally disable the generated Swagger UI by setting doc=False:
from flask import Flask
from flask_restx import Api, Resource, fields
app = Flask(__name__)
api = Api(app, doc=False) # <---
# ...
if __name__ == '__main__':
app.run(debug=True)
This won't work since the .json document is still available even if UI is disabled