Package Data | |
---|---|
Maintainer Username: | ryanaby |
Maintainer Contact: | aby@ryanaby.com (Ryan Aby) |
Package Create Date: | 2020-06-17 |
Package Last Update: | 2020-06-17 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-06 15:04:39 |
Package Statistics | |
---|---|
Total Downloads: | 12 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Manage api key access from .env file.
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 your key on .env
file, you can add more than one key using pipe |
as separator.
AUTH_KEY=y0ur5ecur3K3y|an0th3rSecur3K3y
You can use middleware auth.apikey
on your route.
$router->get('api/post/1', ['middleware' => ['auth.apikey'], function () {
//
}]);
Request must have X-auth-key
headers to have access your API endpoint.
X-auth-key: y0ur5ecur3K3y
The failed authentication will return 401 header
{
"errors": [
{
"message": "Unauthorized Access"
}
]
}
Lumen Auth Key package is open-sourced software licensed under the MIT license.