vinkla / laravel-shield by vinkla

A HTTP basic auth middleware for Laravel
44,085
165
4
Package Data
Maintainer Username: vinkla
Maintainer Contact: hello@doubledip.se (Vincent Klaiber)
Package Create Date: 2016-01-26
Package Last Update: 2019-06-29
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2019-07-21 15:34:28
Package Statistics
Total Downloads: 44,085
Monthly Downloads: 2,528
Daily Downloads: 26
Total Stars: 165
Total Watchers: 4
Total Forks: 10
Total Open Issues: 0

Laravel Shield

shield

A HTTP basic auth middleware for Laravel.

// Use on your routes.
Route::get('/', ['middleware' => 'shield'], function () {
    // Your protected page.
});

// Use it within your controller constructor.
$this->middleware('shield');

// Use specific user credentials.
$this->middleware('shield:hasselhoff');

Build Status Coverage Status Total Downloads Latest Version License

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require vinkla/shield

Add the middleware to the $routeMiddleware array in your Kernel.php file.

'shield' => \Vinkla\Shield\ShieldMiddleware::class,

Configuration

Laravel Shield requires configuration. To get started, you'll need to publish all vendor assets:

$ php artisan vendor:publish

This will create a config/shield.php file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

HTTP Basic Auth Credentials

The user credentials which are used when logging in with HTTP basic authentication.

Usage

To protect your routes with the shield you can add it to the routes file.

Route::get('/', ['middleware' => 'shield'], function () {
    // Your protected page.
});

You can also add the shield middleware to your controllers constructor.

$this->middleware('shield');

The middleware accepts one optional parameter to specify which user credentials to compared with.

$this->middleware('shield:kitt');

To add a new user, you probably want to use hashed credentials. Hashed credentials can be generated with the password_hash() function in the terminal:

$ php -r "echo password_hash('my-secret-passphrase', PASSWORD_DEFAULT);"

Then copy and paste the hashed credentials to the .env environment file.

SHIELD_USER=your-hashed-user
SHIELD_PASSWORD=your-hashed-password

License

MIT © Vincent Klaiber