我正在使用 OpenAPI定义(小部分)现有 API ( Samanage ) 以协助一些集成工作。
我需要使用 Bearer auth 进行身份验证,但通过在Authorize.
服务器期望在一个X-Samanage-Authorization像这个例子一样命名的标头中进行承载身份验证:
curl -H "X-Samanage-Authorization: Bearer <TokenGoesHere>" -H 'Accept: application/vnd.samanage.v2.1+json' -H 'Content-Type: application/json' -X GET https://api.samanage.com/incidents.json
Run Code Online (Sandbox Code Playgroud)
我知道https://swagger.io/docs/specification/authentication/bearer-authentication/,但它似乎并没有完全帮助我。
这(OpenAPI 3)
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
...
security:
- bearerAuth: []
Run Code Online (Sandbox Code Playgroud)
生成名为 default ( Authorization)的身份验证标头
curl -X GET "https://api.samanage.com/incidents/12341234.json" -H "accept: application/json" -H "Authorization: Bearer <TokenGoesHere>"
Run Code Online (Sandbox Code Playgroud)
然后失败(401)。
我觉得我想要这个:
components:
securitySchemes:
bearerAuth:
type: http
name: X-Samanage-Authorization
in: header
scheme: bearer
Run Code Online (Sandbox Code Playgroud)
但这在 Swagger …