Forum Discussion

indhu's avatar
indhu
New Contributor
5 years ago

Api authentication works when provided in query and not in header but actually it is set as a header

Hi all, 

I am new to swagger and in a learning phase. 

 

I have an API with API key in the header which works perfect with postman but when I am trying to document in swagger, it doesn't work.

 

Actually, the API key is set as a header parameter. But in swagger, it works only when it is changed to the query parameter.

 

This doesn't work when setting as a header param

 

security:
  - ApiKeyAuth: [] // key globally declared 
components: // This doesn't work
  securitySchemes:
    ApiKeyAuth:        
      type: apiKey
      in: header  // api key is set as a header
      name: apikey 

This works when set as a query param

security:
  - ApiKeyAuth: [] // key globally declared 
components: // This works
  securitySchemes:
    ApiKeyAuth:        
      type: apiKey
      in: query  // api key is set as a query 
      name: apikey 

Can somebody help me? I am missing something clearly but don't know what.

 

Thanks,

Indhu

No RepliesBe the first to reply