我想向我的 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/