tartan / separ
A HTTP basic auth middleware for Laravel 7+
Requires
- php: ^7.2.5
- illuminate/support: ^7.0
- symfony/http-kernel: ^5.0
Requires (Dev)
- graham-campbell/analyzer: ^2.3
- graham-campbell/testbench: ^5.3
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2020-03-18 14:11:17 UTC
README
Separ means Shield in English
How it's working?
// Use on your routes. Route::get('/', ['middleware' => 'separ'], function () { // Your protected page. }); // Use it within your controller constructor. $this->middleware('separ'); // Use specific user credentials. $this->middleware('MY_USERNAME:MY_SECRET_PASS');
Installation
Require this package, with Composer, in the root directory of your project.
$ composer require tartan/separ
Add the middleware to the $routeMiddleware
array in your Kernel.php
file.
'separ' => \Tartan\Separ\ShieldMiddleware::class,
Configuration
Laravel Separ requires configuration. To get started, you'll need to publish all vendor assets:
$ php artisan vendor:publish
This will create a config/separ.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 separ you can add it to the routes file.
Route::get('/', ['middleware' => 'separ'], function () { // Your protected page. });
You can also add the separ middleware to your controllers constructor.
$this->middleware('separ');
The middleware accepts one optional parameter to specify which user credentials to compared with.
$this->middleware('ANOTHER_USER:ANOTHER_PASS');
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.
SEPAR_USER=your-hashed-user SEPAR_PASSWORD=your-hashed-password
Team
This component is developed by the following person(s) and a bunch of awesome contributors.
Aboozar Ghaffari |
Support This Project
Please contribute in package completion. This is the best support.