PHPackages                             tkhamez/slim-role-auth - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. tkhamez/slim-role-auth

ActiveLibrary[HTTP &amp; Networking](/categories/http)

tkhamez/slim-role-auth
======================

Role-based authorization for the Slim framework

6.0.0(5mo ago)1410.3k2MITPHPPHP ^8.1CI passing

Since Aug 26Pushed 3d ago2 watchersCompare

[ Source](https://github.com/tkhamez/slim-role-auth)[ Packagist](https://packagist.org/packages/tkhamez/slim-role-auth)[ RSS](/packages/tkhamez-slim-role-auth/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (9)Versions (14)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/5462e7deebede76c483c3929cf9a0f445fd81c54fb67b693c07ab3e3702c3591/687474703a2f2f706f7365722e707567782e6f72672f746b68616d657a2f736c696d2d726f6c652d617574682f76)](https://packagist.org/packages/tkhamez/slim-role-auth)[![Total Downloads](https://camo.githubusercontent.com/4c3df2d33aea76a90a8a22ac8a009e569bcd50d702549a6d4cd455b7af0f7ffd/687474703a2f2f706f7365722e707567782e6f72672f746b68616d657a2f736c696d2d726f6c652d617574682f646f776e6c6f616473)](https://packagist.org/packages/tkhamez/slim-role-auth)[![License](https://camo.githubusercontent.com/7ab7c1d1370cd0dde6e970000aa446ccb1af8950bdb0b63a28fe32c57e773cdc/687474703a2f2f706f7365722e707567782e6f72672f746b68616d657a2f736c696d2d726f6c652d617574682f6c6963656e7365)](https://packagist.org/packages/tkhamez/slim-role-auth)[![PHP Version Require](https://camo.githubusercontent.com/ccb7f147053cc7eab1f2de3fe71d3a1b9b4a033ab427884cc7ff28fce9c4f5b4/687474703a2f2f706f7365722e707567782e6f72672f746b68616d657a2f736c696d2d726f6c652d617574682f726571756972652f706870)](https://packagist.org/packages/tkhamez/slim-role-auth)[![build](https://github.com/tkhamez/slim-role-auth/workflows/test/badge.svg)](https://github.com/tkhamez/slim-role-auth/actions)

Role-based authorization
========================

[](#role-based-authorization)

Middleware for the [Slim 4](http://www.slimframework.com/) framework.

For Slim 3 use the 1.0.0 release.

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

[](#installation)

With Composer:

```
composer require tkhamez/slim-role-auth

```

Usage
-----

[](#usage)

Example:

```
use Tkhamez\Slim\RoleAuth\RoleMiddleware;
use Tkhamez\Slim\RoleAuth\SecureRouteMiddleware;

$app = Slim\Factory\AppFactory::create();

// Deny access if a required role is missing.
$app->add(new SecureRouteMiddleware(
    new Slim\Psr7\Factory\ResponseFactory(), // Any implementation of Psr\Http\Message\ResponseFactoryInterface.
    [
        // Route pattern  => Roles, the first "starts-with" match is used.
        '/secured/public' => ['any'],
        '/secured'        => ['user'],
    ],
    ['redirect_url' => null] // Adds the "Location" header instead of a 403 status code if set.
));

// Add roles to request attribute.
$app->add(new RoleMiddleware(
    new App\RoleProvider(), // Any implementation of Tkhamez\Slim\RoleAuth\RoleProviderInterface.
    ['route_pattern' => ['/secured']] // Optionally limit to these routes.
));

// Add routing middleware last, so the Slim router is available from the request.
$app->addRoutingMiddleware();
```

- The `SecureRouteMiddleware` denies access to a route if the required role is missing in the request object.
- The `RoleMiddleware` class adds roles provided by the `RoleProvider` object to the request object.
- You can add multiple role providers for different paths.

For more information, see the inline documentation of the classes.

Dev Env
-------

[](#dev-env)

```
docker build --tag slim-role-auth .
docker run -it --mount type=bind,source="$(pwd)",target=/app --workdir /app slim-role-auth /bin/sh
```

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance87

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 98.2% 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 ~240 days

Recently: every ~397 days

Total

12

Last Release

170d ago

Major Versions

1.0.0 → 2.0.02019-08-04

2.0.1 → 3.0.02020-01-26

3.0.1 → 4.0.02022-12-19

4.0.0 → 5.0.02024-06-01

5.1.0 → 6.0.02025-11-23

PHP version history (7 changes)0.1.0PHP &gt;=5.5.0

2.0.0PHP ^7.1

3.0.0PHP ^7.2

3.0.1PHP ^7.2|^8.0

4.0.0PHP ^7.3|^8.0

5.0.0PHP ^7.4|^8.0

6.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/34757257?v=4)[Tian Khamez](/maintainers/tkhamez)[@tkhamez](https://github.com/tkhamez)

---

Top Contributors

[![tkhamez](https://avatars.githubusercontent.com/u/34757257?v=4)](https://github.com/tkhamez "tkhamez (56 commits)")[![jaywilliams](https://avatars.githubusercontent.com/u/3330?v=4)](https://github.com/jaywilliams "jaywilliams (1 commits)")

---

Tags

authorizationmiddlewareslim-frameworkpsr-7middlewareslimpsr-15authorization

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tkhamez-slim-role-auth/health.svg)

```
[![Health](https://phpackages.com/badges/tkhamez-slim-role-auth/health.svg)](https://phpackages.com/packages/tkhamez-slim-role-auth)
```

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[relay/relay

A PSR-15 server request handler.

3302.1M86](/packages/relay-relay)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

586.6M81](/packages/laminas-laminas-stratigility)[middlewares/utils

Common utils for PSR-15 middleware packages

503.4M92](/packages/middlewares-utils)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)

PHPackages © 2026

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