【问题标题】:Codeigniter REST API Keys not workingCodeigniter REST API 密钥不起作用
【发布时间】:2017-06-17 08:43:34
【问题描述】:

我正在使用chriskacerguis/codeigniter-restserver 创建我的rest api 服务器,我正在尝试启用api 密钥,但他们的问题是即使我按照说明进行操作,我也无法使用任何密钥进行身份验证,即所有请求都通过如果他们在请求中没有 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';

【问题讨论】:

    标签: php rest codeigniter postman api-key


    【解决方案1】:

    使用您的组连接名称

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

    【讨论】:

      【解决方案2】:

      所以我只是一个信使,正如Chris,已经指出问题出在REST_Controller.php,只需添加

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

      在 REST_Controller.php 的第 828 行,问题出在最后一个版本的 codeigniter 3 和最后一个版本的 chriskacerguis/codeigniter-restserver。

      我整天都在与这个作斗争。我只是测试 Chris 解决方案,一切似乎都运行良好。

      【讨论】:

        猜你喜欢
        • 2018-05-14
        • 2016-11-12
        • 1970-01-01
        • 1970-01-01
        • 2015-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-08
        相关资源
        最近更新 更多