PHPackages                             maksimovic/slim-oauth2-middleware - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. maksimovic/slim-oauth2-middleware

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

maksimovic/slim-oauth2-middleware
=================================

OAuth2 middleware for use within a Slim Framework API

v4.0.2(1mo ago)03↓100%1MITPHPPHP ^8.1CI passing

Since Jul 23Pushed 1mo agoCompare

[ Source](https://github.com/maksimovic/slim-oauth2-middleware)[ Packagist](https://packagist.org/packages/maksimovic/slim-oauth2-middleware)[ RSS](/packages/maksimovic-slim-oauth2-middleware/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (9)Versions (23)Used By (1)

Chadicus\\Slim\\OAuth2\\Middleware
==================================

[](#chadicusslimoauth2middleware)

> **Fork Notice:** This is a maintained fork of the abandoned [`chadicus/slim-oauth2-middleware`](https://github.com/chadicus/slim-oauth2-middleware) package. Updated for PHP 8.1+.

[![License](https://camo.githubusercontent.com/734508b359fe427e61876360db5d0c09f026c3a81629ce7688d94f2a31989e01/68747470733a2f2f706f7365722e707567782e6f72672f6d616b73696d6f7669632f736c696d2d6f61757468322d6d6964646c65776172652f6c6963656e7365)](https://packagist.org/packages/maksimovic/slim-oauth2-middleware)

Middleware for using [OAuth2 Server](http://bshaffer.github.io/oauth2-server-php-docs/) within a [Slim Framework](http://www.slimframework.com/) API.

Requirements
------------

[](#requirements)

PHP 8.1 or later.

Installation
------------

[](#installation)

```
composer require maksimovic/slim-oauth2-middleware
```

Example Usage
-------------

[](#example-usage)

```
use Chadicus\Slim\OAuth2\Middleware;
use OAuth2;
use OAuth2\Storage;
use OAuth2\GrantType;
use Slim;

// Set up storage for OAuth2 server
$storage = new Storage\Memory(
    [
        'client_credentials' => [
            'administrator' => [
                'client_id' => 'administrator',
                'client_secret' => 'password',
                'scope' => 'superUser',
            ],
            'foo-client' => [
                'client_id' => 'foo-client',
                'client_secret' => 'p4ssw0rd',
                'scope' => 'basicUser canViewFoos',
            ],
        ],
    ]
);

// Create the OAuth2 server
$server = new OAuth2\Server(
    $storage,
    ['access_lifetime' => 3600],
    [new GrantType\ClientCredentials($storage)]
);

// Create the Slim app
$app = new Slim\App();

// Create the authorization middleware
$authMiddleware = new Middleware\Authorization($server, $app->getContainer());

// No scope required
$app->get('foos', function ($request, $response, $args) {
    // return all foos
})->add($authMiddleware);

// Requires superUser scope OR (basicUser AND canViewFoos)
$app->get('foos/id', function ($request, $response, $id) {
    // return foo details
})->add($authMiddleware->withRequiredScope(['superUser', ['basicUser', 'canViewFoos']]));

// Requires superUser scope
$app->post('foos', function ($request, $response, $args) {
    // create a new foo
})->add($authMiddleware->withRequiredScope(['superUser']));

$app->run();
```

Development
-----------

[](#development)

```
composer install
composer test
composer test:coverage
composer cs-check
```

License
-------

[](#license)

MIT

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance89

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 94.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~185 days

Recently: every ~261 days

Total

22

Last Release

55d ago

Major Versions

v0.2.3 → v1.0.02016-02-04

v1.x-dev → v3.0.02016-05-22

v3.4.0 → v4.0.12026-03-13

v3.4.1 → v4.0.22026-03-18

PHP version history (6 changes)v0.1.0PHP ~5.4 || ~7.0

v1.0.0PHP ~5.5 || ~7.0

v3.0.0PHP ~5.6 || ~7.0

v3.1.1PHP ^5.6 || ^7.0

v3.3.0PHP ^5.6 || ^7.0 || ^8.0

v4.0.1PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d43e10a649dca578689bc02aa4089e26c0d26b1a2f3640dda458973e55adcf10?d=identicon)[maksimovic](/maintainers/maksimovic)

---

Top Contributors

[![chadicus](https://avatars.githubusercontent.com/u/1182337?v=4)](https://github.com/chadicus "chadicus (127 commits)")[![maksimovic](https://avatars.githubusercontent.com/u/1126226?v=4)](https://github.com/maksimovic "maksimovic (6 commits)")[![markfrydrych](https://avatars.githubusercontent.com/u/20677808?v=4)](https://github.com/markfrydrych "markfrydrych (1 commits)")[![soren121](https://avatars.githubusercontent.com/u/295939?v=4)](https://github.com/soren121 "soren121 (1 commits)")

---

Tags

middlewareslimoauth2

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/maksimovic-slim-oauth2-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/maksimovic-slim-oauth2-middleware/health.svg)](https://phpackages.com/packages/maksimovic-slim-oauth2-middleware)
```

###  Alternatives

[league/oauth2-server

A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.

6.6k136.0M248](/packages/league-oauth2-server)[google/auth

Google Auth Library for PHP

1.4k272.7M162](/packages/google-auth)[chadicus/slim-oauth2-middleware

OAuth2 middleware for use within a Slim Framework API

48411.9k1](/packages/chadicus-slim-oauth2-middleware)[filsh/yii2-oauth2-server

OAuth2 Server for PHP

331523.9k12](/packages/filsh-yii2-oauth2-server)[bshaffer/oauth2-server-httpfoundation-bridge

A bridge to HttpFoundation for oauth2-server-php

522.3M12](/packages/bshaffer-oauth2-server-httpfoundation-bridge)[chadicus/slim-oauth2

OAuth2 routes, middleware and utilities for use within a Slim Framework API

129365.9k3](/packages/chadicus-slim-oauth2)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
