symfony-notes/http-basic-authenticator-bundle
A Symfony bundle that adds HTTP Basic authentication support through a dedicated authenticator, making it simple to protect routes and APIs with username and password credentials in your Symfony applications.
This is a Symfony bundle, not a Laravel package — the first step for a Laravel developer is translating the concept rather than expecting composer require to slot into config/app.php. HTTP Basic auth is the same protocol either way: the client sends Authorization: Basic base64(user:pass) on every request, and the server validates it per-request with no session.
Minimal steps:
composer require symfony-notes/http-basic-authenticator-bundle. Because the package has no stars or dependents, read the source in vendor/ before trusting it — check the composer.json for supported Symfony/PHP versions and confirm the authenticator class actually implements AuthenticatorInterface.config/bundles.php (Symfony Flex usually does this automatically; without a Flex recipe you must add it manually).config/packages/security.yaml — either via the built-in http_basic: provider or by referencing the bundle's authenticator under guard/custom_authenticators depending on the Symfony version it targets.stateless: true on the firewall and test with curl -u user:pass https://localhost/api/ping.If you are actually on Laravel, the equivalent first use case is Route::middleware('auth.basic') or Auth::onceBasic() in a middleware — use this bundle only if you are maintaining a Symfony service or building something Symfony-compatible.
Stateless firewall for APIs. The canonical pattern is a dedicated firewall with stateless: true, http_basic (or the bundle's authenticator), and a provider pointing at an in-memory, entity, or custom user provider. No session, no CSRF, no login form — every request carries credentials.
Custom user provider. For token-style credentials or API keys masquerading as passwords, implement UserProviderInterface (or PasswordAuthenticator in newer Symfony) so the bundle's authenticator can resolve a UserInterface from the supplied username. Keep the provider side-effect free and cache-friendly.
Multiple firewalls / route matching. Scope Basic auth to a pattern (e.g. ^/api) so browser-facing routes keep their form login. Order matters: first matching firewall wins, so put the specific pattern above the catch-all main.
Layered on top of another mechanism. A common workflow is Basic auth as a bootstrap/impersonation layer behind an internal network, with a JWT or session authenticator handling the real user flow. Combine by making the Basic authenticator return a populated user and letting the stateless firewall short-circuit on success.
Testing workflow. Use curl -u user:pass, or in PHPUnit set a PHP_AUTH_USER/PHP_AUTH_PW server pair on the request. Assert on 401 with a WWW-Authenticate header for the failure path and 200 plus expected payload for success. Add a test for wrong password and for missing header separately.
Integration tip. Because the credentials are sent on every request, terminate TLS at the edge and configure your reverse proxy to forward the Authorization header (some proxies strip it by default). Document this in the service's README.
WWW-Authenticate drives browser behavior. If the header is missing on 401, browsers won't prompt and API clients can't negotiate. The realm value is cosmetic but should be stable.stateless: true means Symfony starts a session and sets a cookie, silently changing the security model. Verify with Set-Cookie absent in responses.plaintext; storing hashed passwords requires the matching encoder (auto, bcrypt, argon2id). A mismatch yields confusing 401s with no error detail.pattern tightly to avoid credentials being replayed against admin routes.AuthenticatorInterface), 6.x, and 7.x. With zero dependents there is no compatibility signal — check the package's composer.json constraints against your Symfony version before committing.https://user:pass@host is deprecated in many clients; test with explicit headers.bin/console debug:config security confirms the firewall actually picked up the bundle's authenticator.services.yaml to inject a custom user provider or logger. If it hardcodes a listener, prefer decorating the service rather than forking while the package is unmaintained.http_basic firewall unless the bundle adds something you specifically need (e.g. custom challenge headers or per-route realms).How can I help you explore Laravel packages today?