Codeigniter REST API keys do not work

I am using chriskacerguis / codeigniter-restserver to create my api server for relaxing and I am trying to activate api keys, but the problem is that although I followed the instructions, I cannot authenticate using any key, i.e. all requests go through even if they don't have an api header header in the request.

This is my current configuration.

rest.php

$config['rest_keys_table'] = 'keys';
$config['rest_enable_keys'] = TRUE;
$config['rest_key_column'] = 'api_key';
$config['rest_limits_method'] = 'ROUTED_URL';
$config['rest_key_name'] = 'X-API-KEY';

My table was created using the following SQL query.

CREATE TABLE `keys` (
`id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`api_key` varchar(255) NOT NULL,
`level` int(2) NOT NULL,
`ignore_limits` tinyint(1) NOT NULL DEFAULT '0',
`is_private_key` tinyint(1) NOT NULL DEFAULT '0',
`ip_addresses` text,
`date_created` int(11) NOT NULL,
`api_key_activated` enum('yes','no') NOT NULL DEFAULT 'no'
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 INSERT INTO `keys` (`id`, `user_id`, `api_key`, `level`, `ignore_limits`, 
 `is_private_key`, `ip_addresses`, `date_created`, `api_key_activated`) 
 VALUES
 (1, 1, '1234', 10, 0, 0, NULL, 0, 'no'), (1, 1, '12345', 10, 0, 0, NULL, 0, 
 'yes')

The problem is that the request passes no matter what. I have included routes in my project, can this cause a problem?

routes.php

$route['api/v1/foo/(:any)'] = 'Api_v1/foo/$1';
+4
source share
1

, , Chris , REST_Controller.php,

      $this->output->_display();
      exit;

828 REST_Controller.php codeigniter 3 chriskacerguis/codeigniter-restserver.

. , , , .

+1

Source: https://habr.com/ru/post/1668442/


All Articles