6

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';

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Use the name of you group connection

$active_group = 'pdo_mysqli'; /*Local Conetion*/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.