PHPackages                             chadicus/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. chadicus/slim-oauth2-middleware

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

chadicus/slim-oauth2-middleware
===============================

OAuth2 middleware for use within a Slim Framework API

v3.4.0(3y ago)48422.5k↓56.4%19[1 issues](https://github.com/chadicus/slim-oauth2-middleware/issues)1MITPHPPHP ^5.6 || ^7.0 || ^8.0

Since Jul 23Pushed 3y ago5 watchersCompare

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

READMEChangelog (10)Dependencies (9)Versions (20)Used By (1)

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

[](#chadicusslimoauth2middleware)

[![Latest Stable Version](https://camo.githubusercontent.com/b3b652c5b1ebf5e6d2be4d66aff5cbc975a6e347f3d29f004f0ce322e43314ef/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d6d6964646c65776172652f762f737461626c65)](https://packagist.org/packages/chadicus/slim-oauth2-middleware)[![Latest Unstable Version](https://camo.githubusercontent.com/ce73f84386594d8dcdbe1676e0af5fa72801c4daa36093f01c98ce26f34fe266/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d6d6964646c65776172652f762f756e737461626c65)](https://packagist.org/packages/chadicus/slim-oauth2-middleware)[![License](https://camo.githubusercontent.com/86723192ead6581fce182ac1c0074b840f42b36547bae007c9debf9802ffca40/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d6d6964646c65776172652f6c6963656e7365)](https://packagist.org/packages/chadicus/slim-oauth2-middleware)

[![Total Downloads](https://camo.githubusercontent.com/fb2d2925b8ab4d9fef5877229df033eb7f97597ddb24cdc413a740cac6229f2c/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d6d6964646c65776172652f646f776e6c6f616473)](https://packagist.org/packages/chadicus/slim-oauth2-middleware)[![Daily Downloads](https://camo.githubusercontent.com/2d1802207869b42e7e15a109863d2f45cde60350687368baddffb9a18a6f4f4e/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d6d6964646c65776172652f642f6461696c79)](https://packagist.org/packages/chadicus/slim-oauth2-middleware)[![Monthly Downloads](https://camo.githubusercontent.com/5a1f5fe18d6afa524e7398137a52130abea2ab714eeb6d45130fd5c724d338e2/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d6d6964646c65776172652f642f6d6f6e74686c79)](https://packagist.org/packages/chadicus/slim-oauth2-middleware)

[![Documentation](https://camo.githubusercontent.com/a5445bbf0a3a04a2ec4db113f8a4ada4e12b57d9b2de32d936fa17800bc9ca6e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7265666572656e63652d706870646f632d626c75652e7376673f7374796c653d666c6174)](http://pholiophp.org/chadicus/slim-oauth2-middleware)

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

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

[](#requirements)

Chadicus\\Slim\\OAuth2\\Middleware requires PHP 5.6 (or later).

Composer
--------

[](#composer)

To add the library as a local, per-project dependency use [Composer](http://getcomposer.org)! Simply add a dependency on `chadicus/slim-oauth2-middleware` to your project's `composer.json` file such as:

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

Contact
-------

[](#contact)

Developers may be contacted at:

- [Pull Requests](https://github.com/chadicus/slim-oauth2-middleware/pulls)
- [Issues](https://github.com/chadicus/slim-oauth2-middleware/issues)

Project Build
-------------

[](#project-build)

With a checkout of the code get [Composer](http://getcomposer.org) in your PATH and run:

```
composer install
./vendor/bin/phpunit
./vendor/bin/phpcs
```

Community
---------

[](#community)

[![Gitter](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/slim-oauth2/Lobby#)

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

[](#example-usage)

Simple example for using the authorization middleware.

```
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',
            ],
            'bar-client' => [
                'client_id' => 'foo-client',
                'client_secret' => '!password1',
                'scope' => 'basicUser',
            ],
        ],
    ]
);

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

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

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

//Assumes token endpoints available for creating access tokens

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

$getRouteCallback = function ($request, $response, $id) {
    //return details for a foo, requires superUser scope OR basicUser with canViewFoos scope
};

$app->get('foos/id', $getRouteCallback)->add($authMiddleware->withRequiredScope(['superUser', ['basicUser', 'canViewFoos']]));

$postRouteCallback = function ($request, $response, $args) {
    //Create a new foo, requires superUser scope
};

$app->post('foos', $postRouteCallback)->add($authMiddleware->withRequiredScope(['superUser']));

$app->run();
```

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% 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 ~158 days

Recently: every ~487 days

Total

19

Last Release

1152d ago

Major Versions

v0.2.3 → v1.0.02016-02-04

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

PHP version history (5 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

### Community

Maintainers

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

---

Top Contributors

[![chadicus](https://avatars.githubusercontent.com/u/1182337?v=4)](https://github.com/chadicus "chadicus (127 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/chadicus-slim-oauth2-middleware/health.svg)

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[google/auth

Google Auth Library for PHP

1.4k294.2M219](/packages/google-auth)[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.7k147.0M289](/packages/league-oauth2-server)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[simplesamlphp/saml2

SAML2 PHP library from SimpleSAMLphp

30418.0M43](/packages/simplesamlphp-saml2)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)

PHPackages © 2026

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