So I'm currently in the process of developing an an app that will be cross-platform. For this reason I want the app to use an external database on a cloud service through a REST API build using the Zend Framework. I researched on how to build a secure REST API, many resources pointed out using a HMAC for authentication. The part that leaves me a little confused is where should the secret key be generated and how should it be shared with both the server and the client?
Is every individual client (As in every user of the app) supposed to get a unique secret key?
If not, I imagine I could do something like this:
- Generate Secret key for (e.g.) iOS devices on the server.
- Hard code the key in the app
- With every request a HMAC is send hashing the secret key, some data and the user id.
- I check the user id in the HMAC with the user id send in normal JSON, and if the secret keys match.
- execute whatever the user request the user send.
Whenever a third party service would like to use my rest API, I would need to generate a separate secret key specifically for that service.
If every user has to generate a separate secret key, then I have no idea on how I would transfer the key to the server without the risk of a man-in-the-middle attack..
Does this sound about right?