Swagger custom authentication header

KdgDev Source

I'm in the process of applying swagger to a project of mine.

In terms of Authorization, the user can log in with email and password and they'll get an authorization token.

They're then supposed to send this token along with every call, in the header.

So it would be like: MyAuthorization: authKey

Looking at the swagger documentation, it seems that it is only set up to handle OAuth. Is there a way to have swagger handle the authentication my way? I mean in the generated code. I can generate code for the project, it just only has "Basic: ..." as an option.

I'm running swagger 1.3.6, can't upgrade due to dependencies.



answered 3 years ago MikeRalphson #1

From the Swagger 1.2 specs

You can define an authorization object which specifies you are using

  • a type of "apiKey"
  • a passAs of "header", to indicate the key is passed in the request header
  • a keyname of "MyAuthorization", or whatever your header is

comments powered by Disqus