composer require kafkiansky/symfony-basic-auth-middleware
This package works with kafkiansky/symfony-middleware
, install it too, if didn't before:
composer require kafkiansky/symfony-middleware
You can configure user, password, realm and excluded paths, if you want:
## services.yaml
services:
...
Kafkiansky\SymfonyMiddleware\AuthenticateBasic:
arguments:
$user: '%env(BASIC_HTTP_AUTH_USER)%'
$password: '%env(BASIC_HTTP_AUTH_PASSWD)%'
$realm: 'my-app'
$excludedPaths: ## this is optional
- '/test'
$excludedPatterns: ## and this is optional
- '/posts\/\\d+\\/edit/'
use Kafkiansky\SymfonyMiddleware\Attribute\Middleware;
final class SomeController
{
#[Middleware([Kafkiansky\SymfonyMiddleware\AuthenticateBasic::class])]
public function index()
{}
}
## symmidleware.yaml
symiddleware:
global:
- Kafkiansky\SymfonyMiddleware\AuthenticateBasic
## symmidleware.yaml
symiddleware:
groups:
web:
- Kafkiansky\SymfonyMiddleware\AuthenticateBasic
use Kafkiansky\SymfonyMiddleware\Attribute\Middleware;
final class SomeController
{
#[Middleware(['web'])]
public function index()
{}
}
use Kafkiansky\SymfonyMiddleware\Attribute\Middleware;
#[Middleware(['web'])]
final class SomeController
{
public function index()
{}
}
$ composer test
The MIT License (MIT). See License File for more information.