flask-restx icon indicating copy to clipboard operation
flask-restx copied to clipboard

Basic Auth for Swagger UI

Open Bxmnx opened this issue 4 years ago • 2 comments

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.

Bxmnx avatar Sep 22 '21 14:09 Bxmnx

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)

ghost avatar Nov 16 '21 12:11 ghost

This won't work since the .json document is still available even if UI is disabled

dario-collavini avatar Jun 26 '23 14:06 dario-collavini