From 17a0f3bc47d49a58948d584fd1b4d38782637cc6 Mon Sep 17 00:00:00 2001 From: Ashton Smith Date: Thu, 21 Nov 2024 15:01:00 +1300 Subject: [PATCH 1/2] add support for expiring api keys --- src/RestController.php | 4 ++++ src/rest.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/RestController.php b/src/RestController.php index c5fddefb..3c7298c2 100644 --- a/src/RestController.php +++ b/src/RestController.php @@ -880,6 +880,10 @@ protected function _detect_api_key() return false; } + if ($this->config->item('rest_keys_expire')===true && $row->{$this->config->item('rest_keys_expiry_column')} < time()) { + return false; + } + isset($row->user_id) && $this->rest->user_id = $row->user_id; isset($row->level) && $this->rest->level = $row->level; isset($row->ignore_limits) && $this->rest->ignore_limits = $row->ignore_limits; diff --git a/src/rest.php b/src/rest.php index b4cc7984..28cd6ea8 100644 --- a/src/rest.php +++ b/src/rest.php @@ -319,6 +319,7 @@ | `is_private_key` TINYINT(1) NOT NULL DEFAULT '0', | `ip_addresses` TEXT NULL DEFAULT NULL, | `date_created` INT(11) NOT NULL, +| `expires` INT(11) NOT NULL | PRIMARY KEY (`id`) | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | @@ -332,6 +333,7 @@ | is_private_key SMALLINT NOT NULL DEFAULT '0', | ip_addresses TEXT NULL DEFAULT NULL, | date_created INT NOT NULL, +| expires INT NOT NULL, | PRIMARY KEY (id) | ) ; | | @@ -348,6 +350,19 @@ | */ $config['rest_key_column'] = 'key'; +/* +|-------------------------------------------------------------------------- +| REST Table Key Expiry Config and Column Name +|-------------------------------------------------------------------------- +| +| Configure wether or not api keys should expire, and the column name to +| match e.g. expires +| Note: the value in the column will be treated as a unix timestamp and +| compared with php function time() +| +*/ +$config['rest_keys_expire'] = false; +$config['rest_keys_expiry_column'] = 'expires'; /* |-------------------------------------------------------------------------- From f324b6310f5d68d4f4b2c596fae5a8d0914dd748 Mon Sep 17 00:00:00 2001 From: Ashton Smith Date: Thu, 21 Nov 2024 15:07:30 +1300 Subject: [PATCH 2/2] style fixes for #1159 --- src/RestController.php | 2 +- src/rest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RestController.php b/src/RestController.php index 3c7298c2..7f292a98 100644 --- a/src/RestController.php +++ b/src/RestController.php @@ -880,7 +880,7 @@ protected function _detect_api_key() return false; } - if ($this->config->item('rest_keys_expire')===true && $row->{$this->config->item('rest_keys_expiry_column')} < time()) { + if ($this->config->item('rest_keys_expire') === true && $row->{$this->config->item('rest_keys_expiry_column')} < time()) { return false; } diff --git a/src/rest.php b/src/rest.php index 28cd6ea8..7c8c4c9b 100644 --- a/src/rest.php +++ b/src/rest.php @@ -355,9 +355,9 @@ | REST Table Key Expiry Config and Column Name |-------------------------------------------------------------------------- | -| Configure wether or not api keys should expire, and the column name to +| Configure wether or not api keys should expire, and the column name to | match e.g. expires -| Note: the value in the column will be treated as a unix timestamp and +| Note: the value in the column will be treated as a unix timestamp and | compared with php function time() | */