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
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
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
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud