簡體   English   中英

如何指定用於使用 Flask-connexion 和 swagger-2.0 API 驗證基本身份驗證的函數

[英]How to specify the function used to validate the Basic auth with Flask-connexion and swagger-2.0 API

我正在使用帶有 Flask-connexion 的 swagger 2.0 API。

在 swagger.yml 文件中,我將安全定義設置為基本:

  BasicAuth:
    type: basic

然后,我將此安全性添加到我想要保護的路徑中。

# Tenant paths
  /tenant:
    get:
      operationId: tenant.read_all
      tags:
        - Tenant
      summary: Read the entire set of tenants, sorted by name
      description: Read the entire set of tenants, sorted by name
      security:
        - basicAuth: []
      responses:
        200:
          description: Successfully read tenant set operation
          schema:
            type: array
            items:
              $ref: '#/definitions/Tenant'

但我不明白如何指定驗證登錄名和密碼的功能。 在調用路徑函數之前,我需要收集這些參數並進行驗證。

例如,如果這使用 Flask-Login 或 Flask-BasicAuth 隱式定義?

或者應該在沒有 Flask-connexion 的情況下通過在我的 tenant.py 文件中添加代碼來明確完成,例如:

@auth_basic.login_required
def read_all():
...

我希望 Flask-connexion 重定向到驗證登錄名和密碼的 auth 函數,然后重定向到路徑方法/函數。

https://connexion.readthedocs.io/en/latest/security.html#basic-authentication

您必須在 Swagger 文件中定義:

securityDefinitions: basic: type: basic x-basicInfoFunc: app.basic_auth

x-basicInfoFunc將映射到驗證函數,在此示例中,函數basic_auth位於應用程序文件中。

Swagger 的完整示例: https : //github.com/zalando/connexion/tree/master/examples/swagger2/basicauth

OpenApi 的完整示例: https : //github.com/zalando/connexion/tree/master/examples/openapi3/basicauth

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM