Skip to main content
1 of 9
Laiv
  • 14.8k
  • 2
  • 33
  • 71

API keys don't belong to any specific authentication or authorization protocol1. We could use Authorization header but, as you commented, it would take us to implement our own scheme and protocol. Usually reinventing the wheel in security is a bad idea. In order to prevent unexpected behaviours on the HTTP client, we will use custom headers instead.

That being said, remember that the specification for custom headers states that custom headers usually should start with X-.

If I'm allowed to opine, I use always custom headers. This is what I have been doing until now and so far so good. Some frameworks I use also force me to send custom headers. For instance, Swagger.

Finally, keep in mind that we might end up needing a bearer token for authorization and the API key for any other purpose.


1: I find this answer to be very clear regarding API Keys

Note: *Worth to mention that the largest API providers that actually implement API keys (for example Google) use custom headers and supports API keys as request parameter.

Laiv
  • 14.8k
  • 2
  • 33
  • 71