maksimovic/slim-oauth2-middleware

OAuth2 middleware for use within a Slim Framework API

Maintainers

Package info

github.com/maksimovic/slim-oauth2-middleware

pkg:composer/maksimovic/slim-oauth2-middleware

Statistics

Installs: 1 408

Dependents: 1

Suggesters: 1

Stars: 0

5.0.0 2026-04-28 07:43 UTC

README

Fork Notice: This is a maintained fork of the abandoned chadicus/slim-oauth2-middleware package. Updated for PHP 8.1+ and PSR-15.

License

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