basic guard driver provides stateless HTTP Basic authentication backed by the same identity and principal pipeline as the JWT guard. It reads credentials from the standard Authorization: Basic header, validates them through a timing-safe path to prevent user enumeration, resolves the acting principal, and exposes the full contextual surface (Auth::identity(), Auth::principal(), Auth::tenant()) on every authenticated request.
Registering the basic guard
Add a guard entry toconfig/auth.php with driver: basic and point it at a provider:
How it works
On each request, the guard readsPHP_AUTH_USER and PHP_AUTH_PW from the PHP superglobals (via Request::getUser() / Request::getPassword()). If either is absent or empty, the guard returns null from Auth::user() without firing any events.
When credentials are present, the full pipeline runs inside a Timebox:
Attemptingevent fires.- The identity provider looks up the record by the configured
identifier_field. - Laravel’s hasher compares the supplied password against the stored hash.
- If
CanBeActiveis implemented,isActive()is checked on the identity. - The principal resolver runs and
isActive()is checked on the resolved principal. - On success, the identity and principal are bound to the guard and
Auth::user()returns the identity. - On any failure,
Failedfires and the guard returnsnull.
Timebox window (default 400 ms) so the response time does not reveal whether the username exists.
The identifier_field config
By default, the basic guard looks up identities by the email column. You can change this app-wide in authentication.php:
identifier_field key in its config/auth.php entry. The per-guard value takes precedence over the package default.
Multiple basic guards with different identifier fields
You can register multiple basic guards backed by different providers and keyed by different columns. A common pattern is anemail-keyed guard for human users alongside a key_id-keyed guard for per-tenant service credentials:
TenantApiKey implements Identity (and Principal in 2D mode). Its key_id column is what clients supply as the HTTP Basic username, and its password column holds the bcrypt hash of the API secret. The guard hashes and verifies the supplied secret using Laravel’s configured hasher, exactly as it does for user passwords.
Timing constant
Thebasic guard wraps the entire credential validation pipeline in Laravel’s Timebox to prevent timing side-channels. The minimum elapsed time is controlled by:
credentials_microseconds accordingly. Setting it too low defeats the timing-safety guarantee and re-introduces the user-enumeration side-channel the timebox is designed to close.