tuupola/slim-basic-auth
Abandoned PSR-7/PSR-15 middleware providing HTTP Basic Authentication. Originally for Slim but works with any PSR-compatible framework (tested with Slim and Zend Expressive). Configure allowed username/password pairs and protect routes via middleware.
/api, /admin). Supports PCI-DSS, GDPR, or internal security policies requiring authentication for data protection./admin, /dashboard) with minimal setup./api/token for OAuth flows).authenticator parameter./v1/users) while allowing public access to docs (/api-docs).authenticator)./api/* but not /public/*).league/oauth2-server or auth0).symfony/security-bundle).auth:api).*"This lightweight PHP package lets us secure sensitive endpoints (e.g., admin panels, APIs) with HTTP Basic Auth in hours, not weeks. It’s battle-tested (444 GitHub stars), MIT-licensed, and integrates seamlessly with our Slim/Zend Expressive stack. By adopting it, we’ll:
- Reduce risk: Enforce HTTPS and role-based access for critical paths (e.g.,
/api).- Cut costs: Avoid custom dev work (no reinventing BA middleware).
- Future-proof: Supports custom auth (LDAP, databases) via plugins.
- Comply: Meet security policies (PCI, GDPR) for data protection. Alternative: Building this in-house would take 2–3 dev weeks; this costs zero and is production-ready. The abandoned status is a red flag, but the replacement is nearly identical."*
*"tuupola/slim-basic-auth is a PSR-7/PSR-15 middleware for HTTP Basic Auth with these key advantages:
- Zero config for simple cases: Just pass a
usersarray (e.g.,["admin" => "hashed_password"]).- Granular control:
- Protect paths like
/apibut exclude/api/token.- Customize error responses (JSON, HTML) via the
errorcallback.- Hook into auth success/failure with
before/afterfunctions.- Security: Enforces HTTPS by default (configurable for dev/staging).
- Extensible: Replace static users with a PDO authenticator (SQL) or custom callable (LDAP, OAuth).
- Performance: Lightweight (~500 LOC), no dependencies beyond PSR-7.
Tradeoffs:
- Not for OAuth/JWT: Use this for BA only (e.g., admin tools, internal APIs).
- Abandoned but stable: Last update was 2020, but it’s a simple, well-tested middleware. The fork is a drop-in replacement.
- No sessions/tokens: If you need stateful auth, pair this with a session middleware or use Laravel’s auth system.
How to Start:
- Install:
composer require tuupola/slim-basic-auth.- Add to Slim/Zend:
$app->add(new \Tuupola\Middleware\HttpBasicAuthentication([ "path" => "/admin", "users" => ["admin" => password_hash("secret", PASSWORD_BCRYPT)], ]));- For production: Store credentials in
.envor a secrets manager (never commit passwords).Next Steps:
- Demo a protected
/adminroute in staging.- Extend with a
PdoAuthenticatorfor database-backed users.- Compare with the fork for long-term support."*
How can I help you explore Laravel packages today?