intervention/httpauth
Intervention Httpauth is a lightweight Laravel/PHP package for adding HTTP authentication to your app. Protect routes with Basic or Digest auth, integrate easily with middleware, and configure credentials and realms for quick, standards-based access control.
Pros:
Cons:
league/oauth2-client).Auth::attempt()), requiring manual middleware setup.Auth::user()).Route::middleware([HttpAuthMiddleware::class])->group(...);Auth facade instead).use Intervention\HttpAuth\BasicAuth;
use Intervention\HttpAuth\DigestAuth;
Route::get('/protected', function () {
return 'Secret data';
})->middleware(function ($request, $next) {
$auth = new BasicAuth($request);
if (!$auth->validate('username', 'password')) {
abort(401);
}
return $next($request);
});
app/Http/Middleware/HttpAuth.php) for app-wide protection.Auth::extend('http', function ($app) { ... })) for Laravel auth integration (advanced).Authorization: Basic ... or Authorization: Digest ...).hash_hmac() for Digest auth (enabled by default).laravel/sanctum).$response = Http::withHeaders([
'Authorization' => 'Basic ' . base64_encode('user:pass'),
])->get('https://api.example.com');
Authorization field).dd($request->header('Authorization')) to inspect headers.hash_hmac calls).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Credentials leaked (Basic auth) | Unauthorized access | Enforce HTTPS, rotate credentials, use Digest if possible. |
| Digest auth nonce/qop misconfig | Auth failures | Use package defaults or validate manually. |
| Middleware conflict (e.g., CORS) | Broken auth flow | Test middleware order (php artisan route:list). |
| Package abandonment | Unpatched vulnerabilities | Fork or migrate to alternative (e.g., symfony/security). |
| Database dependency (if extended) | Auth validation failures | Cache credentials or use in-memory checks. |
How can I help you explore Laravel packages today?