简体   繁体   English

Swagger Codegen授权用于Python-Flask

[英]Swagger Codegen Authorisation for Python-Flask

I have build a swagger doc, generated the swagger client (python-flask with python2 support). 我已经构建了一个swagger文档,生成了swagger客户端(带有python2支持的python-flask)。

I've built my code up, tested, happy with what I've got. 我已经建立,测试了我的代码,并对自己所拥有的感到满意。 Now I want to secure my API endpoints using https and Basic Auth. 现在,我想使用https和Basic Auth保护我的API端点。

This is v2 of the Open Api Specification (OAS) so I'm setting up as follows (described https://swagger.io/docs/specification/2-0/authentication/basic-authentication/ ) 这是Open Api规范(OAS)的v2,因此我的设置如下(描述为https://swagger.io/docs/specification/2-0/authentication/basic-authentication/

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

Whether I specify that my endpoint have individual security settings or whether I specify this at the root level in the YAML for all endpoints, it makes no difference. 无论是指定端点具有单独的安全设置,还是在YAML的根级别为所有端点指定此设置,都没有区别。

      security:
      - basicAuth: []

I take my YAML, export to JSON, then run the following to rebuild the swagger_server code: 我将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"

What I'm expecting is for the controller or model code to validate that a basic auth header has been passed that matches the authrization specified in the generation code but I see no references anywhere. 我期望控制器或模型代码能够验证是否已传递与生成代码中指定的身份验证相匹配的基本身份验证标头,但我在任何地方都看不到引用。 Not sure if I've just read this wrong or if there's an issue with the way I'm doing it or some of the options I'm using? 不知道我是否读错了此字,或者我的操作方式或使用的某些选项是否有问题?

Python server generated by Swagger Codegen uses Connexion , and Connexion only supports OAuth 2 out of the box. Swagger Codegen生成的Python服务器使用Connexion ,而Connexion 仅支持OAuth 2 As explained in the linked issue, 如链接问题中所述,

users always can add custom mechanisms by decorating their handler functions (see https://github.com/zalando/connexion/blob/master/examples/basicauth/app.py ) 用户始终可以通过装饰其处理函数来添加自定义机制(请参见https://github.com/zalando/connexion/blob/master/examples/basicauth/app.py

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

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