maksimovic / slim-oauth2-middleware
OAuth2 middleware for use within a Slim Framework API
Package info
github.com/maksimovic/slim-oauth2-middleware
pkg:composer/maksimovic/slim-oauth2-middleware
5.0.0
2026-04-28 07:43 UTC
Requires
- php: ^8.1
- bshaffer/oauth2-server-php: ^1.9
- maksimovic/slim-oauth2-http: ^4.0
- psr/http-message: ^1.0 || ^2.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- laminas/laminas-diactoros: ^2.0 || ^3.0
- php-di/php-di: ^7.0
- phpunit/phpunit: ^10.5
- psr/container: ^1.1 || ^2.0
- squizlabs/php_codesniffer: ^3.7
Suggests
- maksimovic/slim-oauth2-routes: Offers standard OAuth2 routes for slim applications
Replaces
README
Fork Notice: This is a maintained fork of the abandoned
chadicus/slim-oauth2-middlewarepackage. Updated for PHP 8.1+ and PSR-15.
PSR-15 middleware for using OAuth2 Server within any PSR-15 compatible framework, including Slim 4.
Requirements
PHP 8.1 or later.
Installation
composer require maksimovic/slim-oauth2-middleware
Example usage
use Chadicus\Slim\OAuth2\Middleware\Authorization; use OAuth2; use OAuth2\Storage; use OAuth2\GrantType; $storage = new Storage\Memory([ 'client_credentials' => [ 'administrator' => ['client_id' => 'administrator', 'client_secret' => 'password', 'scope' => 'superUser'], ], ]); $server = new OAuth2\Server( $storage, ['access_lifetime' => 3600], [new GrantType\ClientCredentials($storage)] ); $auth = new Authorization($server, $container); // Slim 4 $app->get('/foos', $handler)->add($auth); $app->post('/foos', $handler)->add($auth->withRequiredScope(['superUser']));
$container must be either an ArrayAccess or expose a set($key, $value) method (e.g. PHP-DI). The decoded access token is stored under the 'token' key on success and added to the request as the oauth2-token attribute.
Development
composer install
composer test
composer test:coverage
composer cs-check
License
MIT