PHPackages                             chadicus/slim-oauth2-routes - 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. [API Development](/categories/api)
4. /
5. chadicus/slim-oauth2-routes

ActiveLibrary[API Development](/categories/api)

chadicus/slim-oauth2-routes
===========================

OAuth2 routes for use within a Slim Framework API

v3.2.0(3y ago)8399.7k—6.4%101MITPHPPHP ^5.6 || ^7.0 || ^8.0

Since Jul 23Pushed 3y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (6)Versions (19)Used By (1)

Chadicus\\Slim\\OAuth2\\Routes
==============================

[](#chadicusslimoauth2routes)

[![Build Status](https://camo.githubusercontent.com/8e9e638cdfa9de6d521a8a4ceb2e7546fcf713e72f3535ce4e7a38193708b32c/68747470733a2f2f7472617669732d63692e6f72672f63686164696375732f736c696d2d6f61757468322d726f757465732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/chadicus/slim-oauth2-routes)[![Code Quality](https://camo.githubusercontent.com/bb3a368a15833ab3ae9034fd19e9de03f6378e6d72ef8baecdc698df76a67bf7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f63686164696375732f736c696d2d6f61757468322d726f757465732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/chadicus/slim-oauth2-routes/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/1e2c00752dea515fa2cf6e6356bce89d168dcb442f076dad22cee1d2d9e6b4a5/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f63686164696375732f736c696d2d6f61757468322d726f757465732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/chadicus/slim-oauth2-routes?branch=master)

[![Latest Stable Version](https://camo.githubusercontent.com/f19d01b813b5891d6553d4b0a16102a8bd0a0f76deb8f0b197783371031331a9/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d726f757465732f762f737461626c65)](https://packagist.org/packages/chadicus/slim-oauth2-routes)[![Latest Unstable Version](https://camo.githubusercontent.com/f503595a8d0f62c1704a5bc447f26bacd56d47c10c5a33eb83f2b3b62beaec32/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d726f757465732f762f756e737461626c65)](https://packagist.org/packages/chadicus/slim-oauth2-routes)[![License](https://camo.githubusercontent.com/6349cb9091caba8fd539766dd25a683ec88320d0746dad20e34cad3bf781cc0b/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d726f757465732f6c6963656e7365)](https://packagist.org/packages/chadicus/slim-oauth2-routes)

[![Total Downloads](https://camo.githubusercontent.com/50aa19f9a85d3ad09e59f49b34332453d7835fb8b22fb4e0a7e710541fb5571a/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d726f757465732f646f776e6c6f616473)](https://packagist.org/packages/chadicus/slim-oauth2-routes)[![Daily Downloads](https://camo.githubusercontent.com/2606c3c53a739f7b9cb4f6f72a3dadb6ba70bbd9dcccbf48e168a4b4b5e5469d/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d726f757465732f642f6461696c79)](https://packagist.org/packages/chadicus/slim-oauth2-routes)[![Monthly Downloads](https://camo.githubusercontent.com/74c663ea2606c95b19d8bea895f5a42ebbf58557266db3dc92320cb3241aa848/68747470733a2f2f706f7365722e707567782e6f72672f63686164696375732f736c696d2d6f61757468322d726f757465732f642f6d6f6e74686c79)](https://packagist.org/packages/chadicus/slim-oauth2-routes)

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

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

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

[](#requirements)

Chadicus\\Slim\\OAuth2\\Routes 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-routes` to your project's `composer.json` file such as:

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

Contact
-------

[](#contact)

Developers may be contacted at:

- [Pull Requests](https://github.com/chadicus/slim-oauth2-routes/pulls)
- [Issues](https://github.com/chadicus/slim-oauth2-routes/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
```

A Note on Using Views
---------------------

[](#a-note-on-using-views)

The `authorize` and `receive-code` route require `view` objects. The given view object must implement a render method such as the one found in [slim/twig-view](https://github.com/slimphp/Twig-View/blob/master/src/Twig.php#L103) and [slim/php-view](https://github.com/slimphp/PHP-View/blob/master/src/PhpRenderer.php#L64). It would be best if there was a common `ViewInterface` which both implementing but as of now such an interface does not exist.

Community
---------

[](#community)

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

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

[](#example-usage)

```
use Chadicus\Slim\OAuth2\Routes;
use OAuth2;
use OAuth2\GrantType;
use OAuth2\Storage;
use Slim;
use Slim\Views;

//Set-up the OAuth2 Server
$storage = new Storage\Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));
$server = new OAuth2\Server($storage);
$server->addGrantType(new GrantType\AuthorizationCode($storage));
$server->addGrantType(new GrantType\ClientCredentials($storage));

//Set-up the Slim Application
$app = new Slim\App(
    [
        'view' => new Views\PhpRenderer('/path/to/chadicus/slim-oauth2-routes/templates'),
    ]
);

$container = $app->getContainer();

$app->map(['GET', 'POST'], Routes\Authorize::ROUTE, new Routes\Authorize($server, $container['view']))->setName('authorize');
$app->post(Routes\Token::ROUTE, new Routes\Token($server))->setName('token');
$app->map(['GET', 'POST'], Routes\ReceiveCode::ROUTE, new Routes\ReceiveCode($container['view']))->setName('receive-code');
$app->post(Routes\Revoke::ROUTE, new Routes\Revoke($server))->setName('revoke');

//Add custom routes
$slim->get('/foo', function($request, $response, $args) {
    $authorization = $request->getHeaderLine('Authorization');

    //validate access token against your storage

    return $response->withStatus(200);
});

//run the app
$app->run();
```

Authorize and The UserIdProvider
--------------------------------

[](#authorize-and-the-useridprovider)

Within the Authorization route, you can define a `UserIdProviderInterface` to extract the user\_id from the incoming request. By default the route will look in the `GET` query params.

```
class ArgumentUserIdProvider implements UserIdProviderInterface
{
	public function getUserId(ServerRequestInterface $request, array $arguments)
	{
		return isset($arguments['user_id']) ? $arguments['user_id'] : null;
	}
}

//middleware to add user_id to route parameters
$loginMiddelware = function ($request, $response, $next) {
	// Validate the user credentials
	$userId = MyUserService::getUserIdIfValidCredentials($request);
	if ($userId === false) {
		return $response->withStatus(303);
	}

	//Put user_id into the route parameters
	$route = $request->getAttribute('route');
	$route->setArgument('user_id', $userId);

	//Credentials are valid, continue so the authorization code can be sent to the clients callback_uri
	return $next($request, $response);
};

$authorizeRoute = new Routes\Authorize($server, $view, 'authorize.phtml', new ArgumentUserIdProvider());
$app->map(
	['GET', 'POST'],
	Routes\Authorize::ROUTE,
	$authorizeRoute
)->add($loginMiddleware)->setName('authorize');
```

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 96.9% 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 ~167 days

Recently: every ~587 days

Total

18

Last Release

1105d ago

Major Versions

v0.2.1 → v1.0.02016-02-05

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.2PHP ^5.6 || ^7.0

v3.2.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 (126 commits)")[![earllapura](https://avatars.githubusercontent.com/u/6143224?v=4)](https://github.com/earllapura "earllapura (2 commits)")[![jeffdrumgod](https://avatars.githubusercontent.com/u/504327?v=4)](https://github.com/jeffdrumgod "jeffdrumgod (2 commits)")

---

Tags

slimroutingoauth2

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/chadicus-slim-oauth2-routes/health.svg)

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

###  Alternatives

[friendsofsymfony/jsrouting-bundle

A pretty nice way to expose your Symfony routing to client applications.

1.5k53.6M229](/packages/friendsofsymfony-jsrouting-bundle)[phroute/phroute

Fast, fully featured restful request router for PHP

739462.1k29](/packages/phroute-phroute)[softonic/graphql-client

Softonic GraphQL client

1343.3M7](/packages/softonic-graphql-client)[chadicus/slim-oauth2-middleware

OAuth2 middleware for use within a Slim Framework API

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

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

129365.9k3](/packages/chadicus-slim-oauth2)[stevenmaguire/yelp-php

A php client for consuming Yelp API

57396.1k](/packages/stevenmaguire-yelp-php)

PHPackages © 2026

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