【问题标题】:Swagger-ui 2.0 path do not get Bearer Authorization from topSwagger-ui 2.0 路径没有从顶部获得承载授权
【发布时间】:2020-07-19 16:51:40
【问题描述】:

当我检查 swagger 时,我的路径“/customers”显示“没有标头授权”,而我在右上角的“授权”输入中输入了 Bearer 令牌。就像客户的“安全”道具没有链接到一般的安全定义。在 web Swagger 中,GET /Customers 附近的挂锁是灰色并打开的,当我点击它时,它没有显示任何“可用授权”。(邮递员版本正在工作),我找不到原因,你能帮我吗?

在我的 swagger-ui (2.0)json 文件中,我得到了:

"securityDefinitions": {
    "Bearer": {
      "type": "apiKey",
      "name": "Authorization",
      "in": "header",
      "description": "Enter your bearer token in the format **Bearer <token>**"
    }
  },

然后在第二条路径下面我输入了“安全”:

"/customers": {
      "get": {
        "tags": ["Customer Search"],
        "summary": "find a customer by email, name, tel, ...",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "email",
            "in": "query",
            "description": "email",
            "required": true,
            "type": "string"
          },
          {
            "name": "realmCode",
            "in": "query",
            "description": "realmCode",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "send customer json file"
          }
        }

这是我的路线的节点 Express JS 代码的开头:

router.get("/customers", async (req: any, res: any) => {
  if (!req.headers.authorization)
    return res.status(401).json({ error: "no headers authorization" });
  else {
```

【问题讨论】:

    标签: node.js express swagger-ui bearer-token


    【解决方案1】:

    好的,我找到了:

      "security": [{ "Bearer": [] }],
    

    而不是“bearerAuth”:)

    【讨论】:

    • 谢谢兄弟!你问的同时解决了哈哈哈!
    猜你喜欢
    • 1970-01-01
    • 2022-11-24
    • 2021-03-01
    • 2019-07-30
    • 2022-09-27
    • 2016-09-06
    • 2015-12-30
    • 2015-09-12
    • 1970-01-01
    相关资源
    最近更新 更多