ryanaby / lumen-auth-key
Authorize requests using auth key(s)
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/ryanaby/lumen-auth-key
This package is auto-updated.
Last update: 2025-09-18 09:41:07 UTC
README
Manage api key access from .env file.
Installation
Run composer require ryanaby/lumen-auth-key
In your bootstrap/app.php
file, add the Lumen Auth Key provider to Register Service Providers blocks
// $app->register(App\Providers\AppServiceProvider::class); // $app->register(App\Providers\AuthServiceProvider::class); // $app->register(App\Providers\EventServiceProvider::class); $app->register(Ryanaby\LumenAuthKey\Providers\AuthKeyServiceProvider::class);
Add Keys
Add your key on .env
file, you can add more than one key using pipe |
as separator.
AUTH_KEY=y0ur5ecur3K3y|an0th3rSecur3K3y
Usage
Implementing Authorization
You can use middleware auth.apikey
on your route.
$router->get('api/post/1', ['middleware' => ['auth.apikey'], function () { // }]);
Pass Authentication
Request must have X-auth-key
headers to have access your API endpoint.
X-auth-key: y0ur5ecur3K3y
Failed Authentication
The failed authentication will return 401 header
{ "errors": [ { "message": "Unauthorized Access" } ] }
Lumen Auth Key package is open-sourced software licensed under the MIT license.