它不支持令牌认证。这是我为添加它所做的修改。REST_Controller.php 搜索 "switch ($rest_auth) {" 添加这个案例:
case 'token':
$this->_check_token();
break;
然后添加这个函数:
/** Check to see if the user is logged in with a token
* @access protected
*/
protected function _check_token () {
if (!empty($this->_args[$this->config->item('rest_token_name')])
&& $row = $this->rest->db->where('token', $this->_args[$this->config->item('rest_token_name')])->get($this->config->item('rest_tokens_table'))->row()) {
$this->api_token = $row;
} else {
$this->response([
$this->config->item('rest_status_field_name') => FALSE,
$this->config->item('rest_message_field_name') => $this->lang->line('text_rest_unauthorized')
], self::HTTP_UNAUTHORIZED);
}
}
配置/rest.php
// *** Tokens ***
/* Default table schema:
* CREATE TABLE `api_tokens` (
`api_token_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`token` VARCHAR(50) NOT NULL,
`created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`api_token_id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
*/
$config['rest_token_name'] = 'X-Auth-Token';
$config['rest_tokens_table'] = 'api_tokens';