jimtools / basic-auth
PSR-7 and PSR-15 HTTP Basic Authentication Middleware
Requires
- php: ^7.2|^8.0
- psr/http-message: ^1.0.1|^2.0
- psr/http-server-middleware: ^1.0
- tuupola/callable-handler: ^0.3.0|^0.4.0|^1.0
- tuupola/http-factory: ^0.4.0|^1.0.2
Requires (Dev)
- equip/dispatch: ^2.0
- laminas/laminas-diactoros: ^1.3|^2.0|^3.0
- overtrue/phplint: ^3.0|^4.0|^5.0|^6.0
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^8.5.30|^9.0
- rector/rector: ^0.14.5
- symplify/easy-coding-standard: ^11.1
Suggests
None
Provides
None
Conflicts
None
Replaces
This package is auto-updated.
Last update: 2026-10-24 09:41:53 UTC
README
Note
This package is a maintained version of a tuupola/slim-basic-auth, version 1 is forked from 3.x and will remained 100% backward compatible with the original library.
This middleware implements HTTP Basic Authentication. It was originally developed for Slim but can be used with all frameworks using PSR-7 or PSR-15 style middlewares. It has been tested with Slim Framework and Zend Expressive.
use Slim\Factory\AppFactory; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Tuupola\Middleware\HttpBasicAuthentication; require __DIR__ . '/vendor/autoload.php'; $app = AppFactory::create(); $app->addErrorMiddleware(true, true, true); $app->addMiddleware(new HttpBasicAuthentication([ 'users' => ['cosmo' => 'tooManySecrets'], ])); $app->get('/', function (Request $request, Response $response) { $response->getBody()->write('Hello, ' . $request->getServerParams()['PHP_AUTH_USER']); return $response; }); $app->run();
Note
Heads up! You are reading documentation for 3.x branch which is PHP 7.1 and up only. If you are using older version of PHP see the 2.x branch. These two branches are not backwards compatible, see UPGRADING for instructions how to upgrade.
Install
composer require jimtools/basic-auth
composer remove tuupola/slim-basic-auth # migration only
Documentation
GitHub issues are used for only to discuss bugs and new features, for support please use GitHub discussions.
Security
If you discover any security related issues, please email james.read.18@gmail.com instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see LICENSE for more information.