I am using chriskacerguis/codeigniter-restserver to create my rest api server and i am trying to enable api keys but they problem is that even though i followed the instructions,i am unable to authenticate using any key,ie all request go through even if they don't have the api key header in the request.
This is my current config
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 goes through no matter what.I have enabled routes in my project,could that be causing a problem?
routes.php
$route['api/v1/foo/(:any)'] = 'Api_v1/foo/$1';
So I'm just a messenger, as Chris, already point out the problem is in REST_Controller.php, just add
$this->output->_display();
exit;
On line 828 of REST_Controller.php, the problem is with the last release of codeigniter 3, and the last release of chriskacerguis/codeigniter-restserver.
I've been fighting with this all day.I just test Chris solution and everything seems to be working fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With