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

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

ogdev/slim-oauth2-middleware
============================

OAuth2 middleware for use within a Slim Framework API

0335↓50%2PHP

Since Feb 18Pushed 1y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (2)

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

[](#chadicusslimoauth2middleware)

[![Build Status](https://camo.githubusercontent.com/2be14a8e60b4300a2978686b442095e995061df90030e3a949ef4532b654f664/68747470733a2f2f7472617669732d63692e6f72672f63686164696375732f736c696d2d6f61757468322d6d6964646c65776172652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/chadicus/slim-oauth2-middleware)[![Code Quality](https://camo.githubusercontent.com/be4a1b22c557d165006193040bf548c52b35953fec80c8d027ad75d084e0ef2a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f63686164696375732f736c696d2d6f61757468322d6d6964646c65776172652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/chadicus/slim-oauth2-middleware/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/7cc49d343010a3c3e0e110b2ba466d2749059a41c24fcad3576f070da4173505/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f63686164696375732f736c696d2d6f61757468322d6d6964646c65776172652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/chadicus/slim-oauth2-middleware?branch=master)

[![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

20

—

LowBetter than 14% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 92% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b45631c74f84ce39d15e8ca4acd6f4c8f43701693c43e9594fa70714c97ca45?d=identicon)[ogdev](/maintainers/ogdev)

---

Top Contributors

[![chadicus](https://avatars.githubusercontent.com/u/1182337?v=4)](https://github.com/chadicus "chadicus (115 commits)")[![tchapi](https://avatars.githubusercontent.com/u/1944007?v=4)](https://github.com/tchapi "tchapi (6 commits)")[![savritsky](https://avatars.githubusercontent.com/u/5127886?v=4)](https://github.com/savritsky "savritsky (2 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)")

### Embed Badge

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

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

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[beatswitch/lock

A flexible, driver based Acl package for PHP 5.4+

870304.7k2](/packages/beatswitch-lock)[amocrm/amocrm-api-library

amoCRM API Client

182728.5k6](/packages/amocrm-amocrm-api-library)[vonage/jwt

A standalone package for creating JWTs for Vonage APIs

424.1M4](/packages/vonage-jwt)

PHPackages © 2026

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