node.js - 为什么从 Swagger UI 发送的请求中缺少 Authorization header ?

标签 node.js swagger swagger-ui openapi swagger-2.0

我想向我的 Node.js API 添加一个文档,为此我有一个 YAML 文件,我在其中放置了我的定义,swagger 文档位于 localhost:5000/api-doc 并且工作正常。
现在我必须使用以下定义添加 Bearer 授权但 Swagger:

swagger: "2.0"
info:
    version: 1.0.0
    title: My API documentation
    description: >
        My API documentation

host: localhost:5000
basePath: "/v1"
schemes:
    - http
securityDefinitions:
    Bearer:
        type: apiKey
        description: "Value: Bearer "
        name: Authorization
        in: header
paths:
    /users:
        get:
            responses:
                "200":
                    description: "Will send `Authenticated`"
                "403":
                    description: "You do not have necessary permissions for the resource"
测试请求时(我点击右上角的“授权”按钮并输入我的 token )我收到以下错误:

"error": "Authorization header not found.


为什么是Authorization请求中未包含 header ?

最佳答案

securityDefinitions单单是不够的,您还需要添加 security根级别或操作级别的 key 以实际应用安全性。

security:
  - Bearer: []

关于node.js - 为什么从 Swagger UI 发送的请求中缺少 Authorization header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61477056/

相关文章:

ruby-on-rails - 如何使用 grape swagger ui 传递数组?

javascript - NodeJS 在 Swagger 文档中添加授权按钮

node.js - Yaml 文件中的 Swagger 验证失败

swagger - openapi3/swagger 描述文本中的内嵌图像

node.js - KrakenJS : perform POST request over a controller ends with error

javascript - Sequelize 删除查询运行,但不解决 Promise

node.js - 使用 grunt 或 Node 服务器启动服务器时出错

node.js - 使用 multer 上传文件时遇到问题

c# - Swagger 2.0 不支持 : Multiple operations with path

java - 混合使用 Path Param 和 RequestParam 的 Rest API