Skip to content

Commit 7c9a90b

Browse files
committed
Adding some information on authentication and multilingual support
1 parent 3915126 commit 7c9a90b

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ _Note: for 1.7.x support download v2.2 from Downloads tab_
1414

1515
## Installation
1616

17-
Drag and drop the **application/libraries/Format.php** and **application/libraries/REST_Controller.php** files into your application's directories. Either autoload the `REST_Controller` class or `require_once` it at the top of your controllers to load it into the scope.
17+
Drag and drop the **application/libraries/Format.php** and **application/libraries/REST_Controller.php** files into your application's directories. Either autoload the `REST_Controller` class or `require_once` it at the top of your controllers to load it into the scope. Additionally, copy the **rest.php** file from **application/config** in your application's configuration directory.
1818

1919
## Handling Requests
2020

@@ -83,6 +83,42 @@ If you don't specify a response code, and the data you respond with `== FALSE` (
8383

8484
$this->response(array()); // HTTP 404 Not Found
8585

86+
## Multilingual Support
87+
88+
If your application uses language files to support multiple locales, `REST_Controller` will automatically parse the HTTP `Accept-Language` header and provide the language(s) in your actions. This information can be found in the `$this->request->lang` object:
89+
90+
public function __construct()
91+
{
92+
parent::__construct();
93+
94+
if (is_array($this->request->lang))
95+
{
96+
$this->load->language('application', $this->request->lang[0]);
97+
}
98+
else
99+
{
100+
$this->load->language('application', $this->request->lang);
101+
}
102+
}
103+
104+
## Authentication
105+
106+
This class also provides rudimentary support for HTTP basic authentication and/or the securer HTTP digest access authentication.
107+
108+
You can enable basic authentication by setting the `$config['rest_auth']` to `'basic'`. The `$config['rest_valid_logins']` directive can then be used to set the usernames and passwords able to log in to your system. The class will automatically send all the correct headers to trigger the authentication dialogue:
109+
110+
$config['rest_valid_logins'] = array( 'username' => 'password', 'other_person' => 'secure123' );
111+
112+
Enabling digest auth is similarly easy. Configure your desired logins in the config file like above, and set `$config['rest_auth']` to `'digest'`. The class will automatically send out the headers to enable digest auth.
113+
114+
Both methods of authentication can be secured further by using an IP whitelist. If you enable `$config['rest_ip_whitelist_enabled']` in your config file, you can then set a list of allowed IPs.
115+
116+
Any client connecting to your API will be checked against the whitelisted IP array. If they're on the list, they'll be allowed access. If not, sorry, no can do hombre. The whitelist is a comma-separated string:
117+
118+
$config['rest_ip_whitelist'] = '123.456.789.0, 987.654.32.1';
119+
120+
Your localhost IPs (`127.0.0.1` and `0.0.0.0`) are allowed by default.
121+
86122
## Other Documentation / Tutorials
87123

88124
* [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)