Am working with phil sturgeon REST_Controller for codeigniter to create a REST api, so far i’ve been able to create a simple library for generating api keys for the users.
My problem is now sending the api key to the API for each request, how i do this without having to manually send it for every request.
Am working with phil sturgeon REST_Controller for codeigniter to create a REST api, so
Share
You should look into request signing. A great example is Amazon’s S3 REST API.
The overview is actually pretty straightforward. The user has two important pieces of information to use your API, a public user id and a private API Key. They send the public id with the request, and use the private key to sign the request. The receiving server looks up the user’s key and decides if the signed request is valid. The flow is something like this:
key.
/user/update?email=new@example.com./user/update?email=new@example.com&userid=123&sig=some_generated_stringrequest is valid.
This methodology ensures the API key is never sent as part of the communication.
Take a look at PHP’s hash_hmac() function, it’s popular for sending signed requests. Generally you get the user to do something like put all the parameters into an array, sort alphabetically, concatenate into a string and then
hash_hmacthat string to get the sig. In this example you might do:Then add that
$sigonto the REST url as mentioned above.