如何使用 OpenApi 2.O 在标头中将令牌和刷新令牌作为授权传递?

问题描述

我是 OpenApi 的新手,我正在使用 Insomnia 并且我正在尝试通过 Authorization: { "token": "dehxsasn8478snsajsx","refreshToken": "cddjnc5156" } 在标题中,但标题参数名为 Accept,不允许内容类型和授权,因此我必须为此目的使用安全方案,但我应该采用哪种安全方案以及如何传递此结构(授权:{“令牌”:“dehxsasn8478snsajsx”,“refreshToken”:标题中的“cddjnc5156”})让我发疯。这就是我正在尝试的东西..我知道这是错误的,但我被卡住了

securitySchemes:
    ApiKeyAuth:
        type: apiKey
        in: header
        name: Authorization
        content:
           application/json:
             schema:
               type: object
               properties:
                 token:
                   type: string
                   example: "ab"
                 refreshToken:
                   type: string
                   example: "djdjsn"

解决方法

使用 apiKey 作为安全架构

securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: Authorization

并在路径中添加

security:
        - apiKey: []

并在标题传递中

{ "token": "dehxsasn8478snsajsx","refreshToken": "cddjnc5156" }

作为字符串。