Skip to content

Commit 7d816b0

Browse files
committed
Documentation on API keys
1 parent 7c9a90b commit 7d816b0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,29 @@ Any client connecting to your API will be checked against the whitelisted IP arr
119119

120120
Your localhost IPs (`127.0.0.1` and `0.0.0.0`) are allowed by default.
121121

122+
## API Keys
123+
124+
In addition to the authentication methods above, the `REST_Controller` class also supports the use of API keys. Enabling API keys is easy. Turn it on in your **config/rest.php** file:
125+
126+
$config['rest_enable_keys'] = TRUE;
127+
128+
You'll need to create a new database table to store and access the keys. `REST_Controller` will automatically assume you have a table that looks like this:
129+
130+
CREATE TABLE `keys` (
131+
`id` int(11) NOT NULL AUTO_INCREMENT,
132+
`key` varchar(40) NOT NULL,
133+
`level` int(2) NOT NULL,
134+
`ignore_limits` tinyint(1) NOT NULL DEFAULT '0',
135+
`date_created` int(11) NOT NULL,
136+
PRIMARY KEY (`id`)
137+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
138+
139+
The class will look for an HTTP header with the API key on each request. An invalid or missing API key will result in an `HTTP 403 Forbidden`.
140+
141+
By default, the HTTP will be `X-API-KEY`. This can be configured in **config/rest.php**.
142+
143+
$ curl -X POST -H "X-API-KEY: some_key_here" http://example.com/books
144+
122145
## Other Documentation / Tutorials
123146

124147
* [NetTuts: Working with RESTful Services in CodeIgniter](http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/)

0 commit comments

Comments
 (0)