Create Basic Auth and Api-Key Restfull API Codeigniter 3
Config Basic Auth and Api-Key For Codeigniter 3 REST API
- Create table:
CREATE TABLE `keys` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`key` varchar(40) 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` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;2. Insert value to Table
INSERT INTO `keys` (`id`, `user_id`, `key`, `level`, `ignore_limits`, `is_private_key`, `ip_addresses`, `date_created`) VALUES
(NULL, 1, 'yourapikeyhere', 0, 0, 0, NULL, '2018-10-11 13:34:33');3. Search the config then set to:
$config['rest_auth'] = 'basic';
$config['rest_valid_logins'] = ['admin' => '1234'];
$config['rest_keys_table'] = 'keys';
$config['rest_enable_keys'] = TRUE;References:
Get Rahmat Aulia’s stories in your inbox
Join Medium for free to get updates from this writer.
https://www.codexworld.com/codeigniter-rest-api-user-login-registration/
https://dev.to/pardip_trivedi/create-a-rest-api-in-codeigniter-with-basic-authentication-1e7f





