yoctu / api-guardian
Protect your API with a token (objective-php)
Installs: 42 346
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=7.0
- objective-php/application: 1.*
Requires (Dev)
- phpunit/phpunit: ^6.5
- squizlabs/php_codesniffer: ^3.2
README
Protect your pages with a token!
Prerequisites
You will need a project running Objective-PHP to use this package.
If you want to use the user token feauture, you'll need a user with the attribute apiToken
With yoctu/connect you'll need at least connect-common v2.2.3
Installing
The package should be easy to install. You just need to add this repository to your composer.json
composer require yoctu/api-guardian
And add the package to your Application.php with filter(s) if needed.
$this->getStep('auth')
->plug(Apiguardian::class, new UrlFilter('/api/*'))->as('api-guardian')
;
Using the package
Now that the package has been plugged on your application you can setup the one or more token to be used in the configuration.
return [
new Param('api-keys', ['api_key_one', 'api_key_two'])
];
You'll now need to add a token to your request to pass the middleware
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Authorization: api_key_one
Connection: keep-alive
Running the tests
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests
License
This project is licensed under the GNU GPL 3.0 License - see the LICENSE file for details