Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Shield

vinkla/shield image

Shield stats

Downloads
268.4K
Stars
228
Open Issues
0
Forks
26

View on GitHub →

A HTTP basic auth middleware for Laravel

Laravel 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');

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
vinkla photo

I'm just Ken

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Vinkla Shield Related Articles

Access Management in Filament With the Shield Plugin image

Access Management in Filament With the Shield Plugin

Read article
SPOTCon 2022 by Scout APM - Speaker List Announced! image

SPOTCon 2022 by Scout APM - Speaker List Announced!

Read article
Tips for Using Laravel’s Scheduler image

Tips for Using Laravel’s Scheduler

Read article
Protect your webhooks with Laravel Shield image

Protect your webhooks with Laravel Shield

Read article
The Artisan Files: Eric Barnes image

The Artisan Files: Eric Barnes

Read article
The Artisan Files: Matt Stauffer image

The Artisan Files: Matt Stauffer

Read article
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
CodeKudu logo

CodeKudu

Stand-ups, Retrospectives, and 360° Feedback for the entire team. 50% off with code LARAVELNEWS.

CodeKudu
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media