zauni / laravel-shield

A HTTP basic auth middleware for Laravel

Home Page:https://vinkla.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 StyleCI Coverage Status Latest Version License

Installation

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

$ composer require vinkla/shield

Add the service provider to config/app.php in the providers array.

Vinkla\Shield\ShieldServiceProvider::class

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 new user credentials, you probably want to use hashed passwords. Hashed password can be generated with htpasswd command line tool or password_hash() PHP function.

Then copy and paste the credentials to the .env file separating the hashed username and password with a colon.

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

License

MIT © Vincent Klaiber

About

A HTTP basic auth middleware for Laravel

https://vinkla.com/

License:MIT License


Languages

Language:PHP 100.0%