ryanaby/lumen-auth-key

Authorize requests using auth key(s)
13
Install
composer require ryanaby/lumen-auth-key
Latest Version:v1.0.0
License:MIT
Last Updated:Jun 17, 2020
Links: GitHub  ·  Packagist
Maintainer: ryanaby

Lumen Auth Key

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.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

634,760,849 9,707
laravel/framework

The Laravel Framework.

584,532,650 34,931
laravel/tinker

Powerful REPL for the Laravel framework.

493,838,477 7,443
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

408,553,772 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

391,429,217 4,660