Python-Flask 的 Swagger Codegen 授权

Swagger Codegen Authorisation for Python-Flask

我已经构建了一个 swagger 文档,生成了 swagger 客户端(python-flask python2 支持)。

我已经构建、测试了我的代码,对我所得到的感到满意。现在我想使用 https 和基本身份验证来保护我的 API 端点。

这是开放 Api 规范 (OAS) 的 v2,所以我设置如下(描述 https://swagger.io/docs/specification/2-0/authentication/basic-authentication/

swagger: "2.0"
securityDefinitions:
  basicAuth:
    type: "basic"

无论我指定我的端点具有单独的安全设置,还是我在 YAML 的根级别为所有端点指定此设置,都没有区别。

      security:
      - basicAuth: []

我使用我的 YAML,导出到 JSON,然后 运行 下面重建 swagger_server 代码:

java -jar swagger-codegen-cli-2.3.1.jar generate -l python-flask - 
DsupportPython2=true -i swagger.json -a "Authorization: Basic 
Base64encodedstring"

我期望控制器或模型代码验证基本身份验证 header 已通过,该身份验证与生成代码中指定的授权相匹配,但我在任何地方都看不到任何引用。不确定我是不是读错了,或者我的操作方式或我使用的某些选项是否有问题?

Python 由 Swagger Codegen 生成的服务器使用开箱即用的 Connexion, and Connexion only supports OAuth 2。如链接问题中所述,

users always can add custom mechanisms by decorating their handler functions (see https://github.com/zalando/connexion/blob/master/examples/basicauth/app.py)