I'm designing a JSON web API and want to distinguish clients by unique IDs, in order to monitor usage and block malicious/misbehaving clients. The API is NOT encapsulated in a JavaScript library and NOT exclusive to web apps, any client type can use it (desktop, phone, etc.).
The problem is, that the web app (official website) is also a client of the API itself, thus would have to expose its API key. As a result, some user could just extract the key from the JavaScript on the page and use it, instead of generating his own key.
Is it possible to mitigate this problem somehow with some better/smarter design choices, or do I have to live with the fact that anyone using the API in bad faith can exploit this?
I have 100% control over the frontend app (EmberJS) and backend servers (Go), so any alternation can be suggested.
- I'm using rate limiting per session/ip to add an extra protection layer for that case
- The twitter.com page was once also a client of its own API. How did they solve that?
Note: The question is not about authentication or security itself, but how to require 3rd party users to use an API key in addition (!) to authentication!