It should be put in the HTTP Authorization header. The spec is here https://www.rfc-editor.org/rfc/rfc7235
Answer from Darrel Miller on Stack OverflowIt should be put in the HTTP Authorization header. The spec is here https://www.rfc-editor.org/rfc/rfc7235
If you want an argument that might appeal to a boss: Think about what a URL is. URLs are public. People copy and paste them. They share them, they put them on advertisements. Nothing prevents someone (knowingly or not) from mailing that URL around for other people to use. If your API key is in that URL, everybody has it.
Videos
Hello 👋, need your expert opinions.
We were working on implementing API key based authentication to prevent our API from being called anonymously.
We approached it in the same way as everyone does commonly.
It felt good for server to server communication.
Then we realized we have few pages in mvc that calls the api directly through Jquery. ( basically client side ).
As soon as I pass API-KEY in request header, I could see them exposed in the network tab and that started train of thoughts in my mind. ( PS : at this point, I was testing on my local through http)
I talked to other people in company and they said if communication is happening over HTTPS then you are safe, API won't be exposed.
Then I setup both my web and api app over HTTPS, but I could still the key in the network tab.
Luckily in order to call the API, you need to first login into the web as a authorize user, so I feel it's not a problem for us.
Because if user can just interact with API with UI elements then it does not matter if he wants to go extra mile to call api through a hacky way.
But does that means, your keys are not secured even over HTTPS if it's exposed via front-end?
Thanks.