简体   繁体   English

如何使用密码保护 swagger 文档

[英]How to protect swagger documentation with password

I am building a flask app and need to add password for swagger documentation in production, but dont know how.我正在构建一个烧瓶应用程序,需要为生产中的 swagger 文档添加密码,但不知道如何。 Here is my code:这是我的代码:

api = Api(
    version='1.0',
    title='API',
    description='Main API',
    doc='/doc',
    authorizations=authorizations)
...
api.init_app(app)

This documentation shouldnt be public for anyone to see, right?这个文档不应该公开给任何人看,对吗? but i cant find a way to add password to it.但我找不到添加密码的方法。 Any suggestion would be awsome.任何建议都会很棒。

I know its very late, but still.我知道很晚了,但仍然如此。

class MyApi(Api):
    def render_doc(self):
        view = super().render_doc()
        if current_user.is_authenticated and current_user.has_role('admin'):
            return view
        return redirect(url_for('security.login', next=request.url))

You need to modify this method which returns end view function.您需要修改这个返回端视图函数的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM