如何解决在Swagger 2.0中使用JWT令牌进行承载身份验证
我正在使用swagger 2.0,并希望使用Bearer Authentication安全机制,在该机制中,我想在标头中传递访问令牌。我尝试使用oauth
安全机制,但无法在API中获得授权。
在下面的代码中,我尝试使用api_Key
,但即使这样也无法正常工作。
swagger: "2.0"
info:
description: ""
version: "1.0.0"
title: "Example Application"
host: "host.com"
basePath: "/dev"
tags:
- name: "company"
description: "All company related endpoints"
schemes:
- "https"
- "http"
paths:
/companies:
post:
tags:
- "company"
summary: "Create a new company"
security:
- api_key: []
description: ""
operationId: "addCompany"
produces:
- "application/json"
parameters:
- in: "body"
name: "body"
description: ""
required: true
schema:
type: "object"
required:
- name
properties:
name:
type: "string"
email:
type: "string"
responses:
"200":
description: "successful operation"
schema:
$ref: "#/definitions/Company"
"400":
description: "Invalid Company"
securityDefinitions:
api_key:
type: "apiKey"
name: "api_key"
in: "header"
definitions:
Company:
type: "object"
required:
- "name"
properties:
id:
type: "string"
name:
type: string
email:
type: string
externalDocs:
description: "Find out more about Swagger"
url: "http://swagger.io"
生成的curl请求如下:-
curl -X POST "https://host.com/dev/companies" -H "accept: application/json" -H "api_key: jnhgvfctrdyuiojnkbhgvcftyuijnkbvfytguhi" -H "Content-Type: application/json" -d "{ \"name\": \"string\",\"email\": \"string\"}"
我希望拥有api_Key
,而不是--header 'Authorization: Bearer access_token
。
任何输入都将非常有帮助。 TIA
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。