Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5160cc
commit 22e16d2
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
defined('BASEPATH') OR exit('No direct script access allowed'); | ||
|
||
$config['api_key_header'] = "X-API-KEY"; | ||
|
||
$config['uri_auth'] = [ | ||
'basic/auth' => [RESTAuth::BASIC] | ||
]; | ||
|
||
$config['auth_callbacks'] = [ | ||
|
||
RESTAuth::CUSTOM('X-APP-ID') => function (&$context, $value):bool { | ||
return true; | ||
}, | ||
|
||
RESTAuth::CUSTOM('X-DEVICE-ID') => function (&$context, $value):bool { | ||
return true; | ||
}, | ||
|
||
RESTAuth::BEARER => function (&$context, $token):bool { | ||
return true; | ||
}, | ||
|
||
RESTAuth::OAUTH2 => function (&$context, $token):bool { | ||
return true; | ||
} | ||
|
||
]; | ||
|
||
$config['response_callbacks'] = [ | ||
|
||
RESTResponse::BAD_REQUEST => function(&$auth):void { | ||
echo(json_encode([ | ||
'error' => 'Bad Request' | ||
])); | ||
}, | ||
|
||
RESTResponse::UN_AUTHORIZED => function(&$auth):void { | ||
echo (json_encode([ | ||
'error' => 'Un-Authorized' | ||
])); | ||
}, | ||
|
||
RESTResponse::NOT_ACCEPTABLE => function(&$auth):void { | ||
echo (json_encode([ | ||
'error' => 'Not Acceptable' | ||
])); | ||
}, | ||
|
||
RESTResponse::NOT_IMPLEMENTED => function(&$auth): void { | ||
echo (json_encode([ | ||
'error' => "$auth Authentication not implemented" | ||
])); | ||
} | ||
]; | ||
|
||
$config['api_limiter'] = [ | ||
'api_limiter' => true, | ||
'per_hour' => 100, | ||
'show_header' => true, | ||
'header_prefix' => 'X-RateLimit-', | ||
'limit_by_ip' => true, | ||
'ip_per_hour' => 50, | ||
'whitelist' => [ | ||
'127.0.0.1', | ||
'::1' | ||
] | ||
]; | ||
|
||
$config['basic_auth'] = [ | ||
'users_table' => 'users', | ||
'id_column' => 'id', | ||
'email_column' => 'email', | ||
'password_column' => 'password', | ||
'username_column' => 'username' | ||
]; | ||
|
||
$config['api_key_auth'] = [ | ||
'api_key_table' => 'api_keys', | ||
'api_key_column' => 'api_key', | ||
'api_key_limit_column' => '_limit', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# TABLE: rest_api_rate_limit | ||
# | ||
CREATE TABLE IF NOT EXISTS rest_api_rate_limit (client VARCHAR(255) NOT NULL DEFAULT "", | ||
_group VARCHAR(255) NOT NULL DEFAULT "_ip_address", start TIMESTAMP NOT NULL DEFAULT | ||
CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, count INT(11) NOT NULL DEFAULT 1, | ||
PRIMARY KEY (client, _group)) ENGINE=InnoDB; | ||
|
||
#@@@ | ||
|
||
# | ||
# TABLE: users | ||
# | ||
CREATE TABLE IF NOT EXISTS users (id INT(7) AUTO_INCREMENT PRIMARY KEY, username VARCHAR(20) | ||
NOT NULL, password TEXT NOT NULL, email VARCHAR(30) NOT NULL) Engine=InnoDB; | ||
|
||
#@@@ | ||
|
||
# | ||
# TABLE: api_keys | ||
# | ||
CREATE TABLE IF NOT EXISTS api_keys (id INT(7) AUTO_INCREMENT PRIMARY KEY, api_key TEXT, | ||
api_secret TEXT, _limit TINYINT DEFAULT 1, user_id INT(9) NOT NULL, app_id TEXT, | ||
FOREIGN KEY (user_id) REFERENCES users(id)) Engine=InnoDB; | ||
|
||
#@@@ | ||
|
||
# Inserts | ||
|
||
INSERT INTO users (id, username, password, email) VALUES (1, 'francis94c', | ||
'$2y$10$eSvuRvrZe./d.a/g4EuokepXntP.rwAf.ibpNZ/CDKaOqYW2mWHf.', 'francis@email.com'); | ||
|
||
#@@@ | ||
|
||
INSERT INTO api_keys (id, api_key, api_secret, _limit, user_id, app_id) VALUES ( | ||
1, 'ABCDE', 'abcdefghijklmnopqrstuvwxyz', 1, 1, '01234567890'); |