2017-01-31 45 views
4

我正在使用chriskacerguis/codeigniter-restserver創建我的休息api服務器,我試圖啓用api密鑰,但他們的問題是,即使我按照說明操作,我無法使用任何密鑰進行身份驗證,即全部即使請求中沒有api密鑰標頭,請求也會通過。Codeigniter REST API密鑰不能正常工作

這是我目前的配置

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

我的表是使用下面的SQL查詢創建。

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

問題是無論如何,請求都會經過。我在我的項目中啓用了路由,是否會導致問題?

routes.php文件

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

回答

1

所以我只是一個使者,爲Chris,已經點出了問題的REST_Controller.php,只需添加

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

在REST_Controller的828線.php,問題在於codeigniter 3的最後一個版本,以及chriskacerguis/codeigniter-restserver的最新版本。

我一直在爲這一整天奮鬥。我只是測試克里斯解決方案,一切似乎都工作正常。