我如何表示“授权:承载 <token>"在 Swagger 规范中 (swagger.json) [英] How can I represent 'Authorization: Bearer <token>' in a Swagger Spec (swagger.json)

查看:23
本文介绍了我如何表示“授权:承载 <token>"在 Swagger 规范中 (swagger.json)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图传达身份验证/安全方案需要设置如下标头:

I am trying to convey that the authentication/security scheme requires setting a header as follows:

Authorization: Bearer <token>

这是我基于 大摇大摆的文档:

securityDefinitions:
  APIKey:
    type: apiKey
    name: Authorization
    in: header
security:
  - APIKey: []

推荐答案

也许这会有所帮助:

swagger: '2.0'
info:
  version: 1.0.0
  title: Based on "Basic Auth Example"
  description: >
    An example for how to use Auth with Swagger.

host: basic-auth-server.herokuapp.com
schemes:
  - http
  - https
securityDefinitions:
  Bearer:
    type: apiKey
    name: Authorization
    in: header
paths:
  /:
    get:
      security:
        - Bearer: []
      responses:
        '200':
          description: 'Will send `Authenticated`'
        '403': 
          description: 'You do not have necessary permissions for the resource'

您可以在此处复制和粘贴:http://editor.swagger.io/#/ 以查看结果.

You can copy&paste it out here: http://editor.swagger.io/#/ to check out the results.

swagger 编辑器网页中还有几个示例,它们具有更复杂的安全配置,可以帮助您.

There are also several examples in the swagger editor web with more complex security configurations which could help you.

这篇关于我如何表示“授权:承载 &lt;token&gt;"在 Swagger 规范中 (swagger.json)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆