There are a myriad of different ways to secure requests to agent URLs. By default, all requests have three simple security features:
- the unique URL for each device is randomly generated during the BlinkUp process;
- the commands required to activate the agent are unknown to anyone but the developers; and
- all requests to https://agent.electricimp.com are SSL encrypted which prevents anyone from sniffing the contents of any request.
For many applications, this encryption plus obfuscation is sufficient security, especially if the requests to the agent are coming from a server or a controlled application. If further security/obfuscation is required we propose a few simple and common methods here. These methods also provide a bonus feature that, if the security is compromised at any point in the future, the parameters can be easily changed to reassert the security.
The four examples are:
- simple_auth_1 - this is the neatest and least visible technique as the shared API key is delivered "out of band" in the HTTP headers. This is the recommended approach.
- simple_auth_2 - this approach requires that an extra query parameter be added to the end of every request containing the API key. This approach works best when the development tools available are very simple and don't allow for HTTP headers to be added.
- simple_auth_3 - this is a simple but rarely seen technique for embedding the API key into the URL path itself. Again, this works best when the development tools available are very simple and don't allow for HTTP headers to be added.
- rocky_auth_4 - the final example demonstrates one approach to using the Rocky framework for creating powerful RESTful APIs in agents. There are other built-in functions that simplify the process of responding to HTTP requests and is roughly modelled on the Express framework for Node.js.
All of these techniques are limited to API calls from servers or applications and are not effective security measures for use by a web browser. Different techniques, usually involving unique users, login prompts and session authentication should be considered. Alternatives such as third-party OAuth authentication are particularly effective if your user base overlaps with other services such as Google, Facebook or Twitter.