You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -119,6 +119,29 @@ Any client connecting to your API will be checked against the whitelisted IP arr
119
119
120
120
Your localhost IPs (`127.0.0.1` and `0.0.0.0`) are allowed by default.
121
121
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
+
122
145
## Other Documentation / Tutorials
123
146
124
147
*[NetTuts: Working with RESTful Services in CodeIgniter](http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/)
0 commit comments