OpenAPI 3 Custom type in Authorization header

风格不统一 提交于 2020-02-25 21:32:04

问题


I am looking for the proper way to specify an Authorization header with a custom type like ApiKey in openAPI 3.

The custom Authorization header should look like

Authorization: ApiKey myAPIKeyHere

All my attempts to specify the securitySchemes entry with type apiKey seems to produce other results...

The closest I got is something like:

securitySchemes:
  ApiKeyAuth:
    type: apiKey
    in: header
    name: ApiKey

... but then, the key is not in the Authorization header.

How can such a requirement be specified?


回答1:


I think I have found a way that seems acceptable - although not perfect. Would like to see something better in the future...

It seems that there is no other way than to add the custom type to the value (aided by a description like below).

components:
  securitySchemes:
      ApiKey:
         type: apiKey
         name: Authorization
         in: header
         description: 'Prefix the value with \"ApiKey\" to indicate the custom authorization type' 
security:
   - ApiKey: []

This does at least produce the correct header in curl (if applied correctly).




回答2:


Please try this:

  securitySchemes:
    ApiKeyAuth:
       type: apiKey
       in: header
       name: ApiKey
  security
    - ApiKeyAuth: []

Please have a look at the documentation:

-> Step 2. Applying security

Authentication and Authorization



来源:https://stackoverflow.com/questions/59694733/openapi-3-custom-type-in-authorization-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!