hmac.rst 1.8 KB

1234567891011121314151617181920212223242526272829303132
  1. HMAC Authentication
  2. ===================
  3. Elgg's RESTful API framework provides functions to support a `HMAC`_ signature scheme for API authentication. The client must send the HMAC signature together with a set of special HTTP headers when making a call that requires API authentication. This ensures that the API call is being made from the stated client and that the data has not been tampered with.
  4. .. _HMAC: http://en.wikipedia.org/wiki/HMAC
  5. The HMAC must be constructed over the following data:
  6. - The public API key identifying you to the Elgg api server as provided by the APIAdmin plugin
  7. - The private API Key provided by Elgg (that is companion to the public key)
  8. - The current unix time in seconds
  9. - A nonce to guarantee two requests the same second have different signatures
  10. - URL encoded string representation of any GET variable parameters, eg ``method=test.test&foo=bar``
  11. - If you are sending post data, the hash of this data
  12. Some extra information must be added to the HTTP header in order for this data to be correctly processed:
  13. - **X-Elgg-apikey** - The public API key
  14. - **X-Elgg-time** - Unix time used in the HMAC calculation
  15. - **X-Elgg-none** - a random string
  16. - **X-Elgg-hmac** - The HMAC as base64 encoded
  17. - **X-Elgg-hmac-algo** - The algorithm used in the HMAC calculation - eg, sha1, md5 etc.
  18. If you are sending POST data you must also send:
  19. - **X-Elgg-posthash** - The hash of the POST data
  20. - **X-Elgg-posthash-algo** - The algorithm used to produce the POST data hash - eg, md5
  21. - **Content-type** - The content type of the data you are sending (if in doubt use application/octet-stream)
  22. - **Content-Length** - The length in bytes of your POST data
  23. Elgg provides a sample API client that implements this HMAC signature: send_api_call(). It serves as a good reference on how to implement it.