Suppose I am developing a mobile application that makes calls to an API server. The API server is secured by an API Key.
I cannot hard-code the API Key inside the mobile application because it can be stolen.
How can I protect the API key?
How is that problem usually solved?
(It sounds like the API-key you are trying to protect is for an API service that you don't own.)
One approach is by using an authentication server. The private API-key is kept on the authentication server and only shared after a valid login.
So how does this work?
Architecturally, you would need a separate authentication server which would leave you with 2 different servers:
Some API-key server that you need a private API-key to use
Authentication server (used to verify user login and exchange private API-keys)
A second approach is to use a pass through server. The private API-key is never shared in this approach. It is possible to add authentication onto the pass-thru server, but not required.
So how does this work?
In this case, you own the pass-thru server so you never need to share your API keys and user authentication is optional.