Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Basic Authentication Codeigniter rest API

Hello i am having a problemm to understand how to enable basic authentication using CodeIgniter and using the https://github.com/chriskacerguis/codeigniter-restserver. The rest.php:

|--------------------------------------------------------------------------
| REST Login
|--------------------------------------------------------------------------
|
| Set to specify the REST API requires to be logged in
|
| FALSE     No login required
| 'basic'   Unsecure login
| 'digest'  More secure login
| 'session' Check for a PHP session variable. See 'auth_source' to set the
|           authorization key
|
*/
$config['rest_auth'] = 'basic';

i enable the basic auth and below i have this:

/*
|--------------------------------------------------------------------------
| REST Login Usernames
|--------------------------------------------------------------------------
|
| Array of usernames and passwords for login, if ldap is configured this is ignored
|
*/
$config['rest_valid_logins'] = ['admin' => '1234'];

if i use admin as username and 1234 as password the login is fine. My question is how can i register users to my database and also update the valid logins config? When the user registers i dont have to go to rest.php and add the record to $config['rest_valid_logins'] but it will be done automatically?

Any help will be appreciated!!!

like image 968
BRG Avatar asked Oct 18 '22 08:10

BRG


1 Answers

Instead of use the basic login, you can create API keys for your REST server.

Each user created in you platform will need a record in the key's table. Those keys need to be sent in the header of each request.

Please, check the rest.php file. There's the CREATE TABLE statement for the key's table.

You need to change these three settings:

$config['rest_keys_table'] with the name of table.

$config['rest_enable_keys'] with the true value.

$config['rest_key_column'] with the column responsible for storage the key data.

Therefore, each request will be treated by CodeIgniter, who will check if the API key sent in the header is valid.

like image 91
Luciano Carvalho Avatar answered Oct 21 '22 00:10

Luciano Carvalho