PHPackages                             mimmi20/mezzio-generic-authorization - 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. mimmi20/mezzio-generic-authorization

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

mimmi20/mezzio-generic-authorization
====================================

Provides a Generic Authorization middleware for Mezzio.

5.0.2(7mo ago)2515.8k↑106.3%211MITPHPPHP ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Jan 7Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/mimmi20/mezzio-generic-authorization)[ Packagist](https://packagist.org/packages/mimmi20/mezzio-generic-authorization)[ Docs](https://github.com/mimmi20/mezzio-generic-authorization)[ RSS](/packages/mimmi20-mezzio-generic-authorization/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (23)Versions (25)Used By (11)

mezzio-generic-authorization
============================

[](#mezzio-generic-authorization)

[![Latest Stable Version](https://camo.githubusercontent.com/876fa7a6cfff36eff61e369dc94c15dc4ff6d99360ccca1ece74ae00e74351ef/68747470733a2f2f706f7365722e707567782e6f72672f6d696d6d6932302f6d657a7a696f2d67656e657269632d617574686f72697a6174696f6e2f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/mimmi20/mezzio-generic-authorization)[![Latest Unstable Version](https://camo.githubusercontent.com/52c0d566c7d45516b55d240a6b816ef08c219b0f39d4130daa797076575c6b75/68747470733a2f2f706f7365722e707567782e6f72672f6d696d6d6932302f6d657a7a696f2d67656e657269632d617574686f72697a6174696f6e2f762f756e737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/mimmi20/mezzio-generic-authorization)[![License](https://camo.githubusercontent.com/b9dba545e8048e98a7aaa5a77e1c870b4a9650ad35d11e437c1d1d27d16f5fa6/68747470733a2f2f706f7365722e707567782e6f72672f6d696d6d6932302f6d657a7a696f2d67656e657269632d617574686f72697a6174696f6e2f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/mimmi20/mezzio-generic-authorization)

Code Status
-----------

[](#code-status)

[![codecov](https://camo.githubusercontent.com/f9b869b41dfcc5864fe34c28151bb73c02923f181833fd281017fed95375ebd3/68747470733a2f2f636f6465636f762e696f2f67682f6d696d6d6932302f6d657a7a696f2d67656e657269632d617574686f72697a6174696f6e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/mimmi20/mezzio-generic-authorization)[![Average time to resolve an issue](https://camo.githubusercontent.com/65682539619d855f1174d561ee38f7d4ec16fab8d84967cd9f34a7b4e39c9669/68747470733a2f2f697369746d61696e7461696e65642e636f6d2f62616467652f7265736f6c7574696f6e2f6d696d6d6932302f6d657a7a696f2d67656e657269632d617574686f72697a6174696f6e2e737667)](https://isitmaintained.com/project/mimmi20/mezzio-generic-authorization "Average time to resolve an issue")[![Percentage of issues still open](https://camo.githubusercontent.com/8c64dbce98976e9750abe22ab6c3bc45c97ca5fd5aaee4a20f76a48369883f36/68747470733a2f2f697369746d61696e7461696e65642e636f6d2f62616467652f6f70656e2f6d696d6d6932302f6d657a7a696f2d67656e657269632d617574686f72697a6174696f6e2e737667)](https://isitmaintained.com/project/mimmi20/mezzio-generic-authorization "Percentage of issues still open")[![Mutation testing badge](https://camo.githubusercontent.com/75d172fb6a98482f265d5ba76b1622db36042fc8bb9f37d61b7f10dc7a9206a4/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d2532466d696d6d6932302532466d657a7a696f2d67656e657269632d617574686f72697a6174696f6e2532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/mimmi20/mezzio-generic-authorization/master)

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

[](#installation)

You can install the mezzio-generic-authorization library with [Composer](https://getcomposer.org):

```
composer require mimmi20/mezzio-generic-authorization
```

Introduction
------------

[](#introduction)

This component provides middleware for [Mezzio](https://github.com/mezzio/mezzio)and [PSR-7](https://www.php-fig.org/psr/psr-7/) applications for authorizing specific routes based on [ACL](https://en.wikipedia.org/wiki/Access_control_list)or [RBAC](https://en.wikipedia.org/wiki/Role-based_access_control) systems.

Unlike in [mezzio-authorization](https://github.com/mezzio/mezzio-authorization) this library does not require the `ServerRequestInterface` by default. This makes it possible to use this component in combination with [mezzio-navigation](https://github.com/mimmi20/mezzio-navigation).

If you are using the provided midleware, the **route name** is used as the resource.

An authorization system first needs authentication: to verify that an identity has access to something (i.e., is authorized) we first need the *identity*, which is provided during authentication.

Authentication is provided via the package [mezzio-authentication](https://docs.mezzio.dev/mezzio-authentication/). That library provides an `AuthenticationMiddleware` class that verify credentials using the HTTP request, and stores the identity via a [PSR-7 request attribute](https://docs.mezzio.dev/mezzio/v3/cookbook/passing-data-between-middleware/).

The identity generated by mezzio-authentication is stored as the request attribute `Mezzio\Authentication\UserInterface` as a `UserInterface` implementation. That interface looks like the following:

```
namespace Mezzio\Authentication;

interface UserInterface
{
    /**
     * Get the unique user identity (id, username, email address or ...)
     */
    public function getIdentity() : string;

    /**
     * Get all user roles
     *
     * @return Iterable
     */
    public function getRoles() : iterable;

    /**
     * Get a detail $name if present, $default otherwise
     */
    public function getDetail(string $name, $default = null);

    /**
     * Get all the details, if any
     */
    public function getDetails() : array;
}
```

mezzio-generic-authorization consumes this identity attribute. It checks if a user's role (as retrieved from the `UserInterface` object) is authorized (granted) to the perform the current HTTP request.

Authorization is performed using the `isGranted()` method of the AuthorizationInterface

```
public function isGranted(?string $role = null, ?string $resource = null, ?string $privilege = null, ?\Psr\Http\Message\ServerRequestInterface\ServerRequestInterface $request = null): bool;
```

Two adapters are available:

- [mezzio-generic-authorization-rbac](https://github.com/mimmi20/mezzio-generic-authorization-rbac/), which implements Role-Based Access Controls ([RBAC](https://en.wikipedia.org/wiki/Role-based_access_control))
- [mezzio-generic-authorization-acl](https://github.com/mimmi20/mezzio-generic-authorization-acl/), which implements an Access Control List ([ACL](https://en.wikipedia.org/wiki/Access_control_list)).

> If you want to know more about authentication using middleware in PHP, we suggest reading the blog post ["Authorize users using Middleware"](https://framework.zend.com/blog/2017-05-04-authorization-middleware.html).

Authorization adapters
----------------------

[](#authorization-adapters)

You can configure the authorization adapter to use via your service container configuration. Specifically, you can either map the service name `Mimmi20\Mezzio\GenericAuthorization\AuthorizationInterface` to a factory, or alias it to the appropriate service.

For instance, using [Mezzio container configuration](https://docs.mezzio.dev/mezzio/v3/features/container/config/), you could select the mezzio-authorization-acl adapter in either of the following ways:

- Using an alias:

    ```
    use Mimmi20\Mezzio\GenericAuthorization\AuthorizationInterface;
    use Mimmi20\Mezzio\GenericAuthorization\Acl\LaminasAcl;

    return [
        'dependencies' => [
            // Using an alias:
            'aliases' => [
                AuthorizationInterface::class => LaminasAcl::class,
            ],
        ],
    ];
    ```
- Mapping to a factory:

    ```
    use Mimmi20\Mezzio\GenericAuthorization\AuthorizationInterface;
    use Mimmi20\Mezzio\GenericAuthorization\Acl\LaminasAclFactory;

    return [
        'dependencies' => [
            // Using a factory:
            'factories' => [
                AuthorizationInterface::class => LaminasAclFactory::class,
            ],
        ],
    ];
    ```

We provide two different adapters.

- The RBAC adapter is provided by [mezzio-generic-authorization-rbac](https://github.com/mimmi20/mezzio-generic-authorization-rbac/).
- The ACL adapter is provided by [mezzio-generic-authorization-acl](https://github.com/mimmi20/mezzio-generic-authorization-acl/).

Each adapter is installable via [Composer](https://getcomposer.org):

```
composer require mimmi20/mezzio-generic-authorization-rbac
# or
composer require mimmi20/mezzio-generic-authorization-acl
```

License
-------

[](#license)

This package is licensed using the MIT License.

Please have a look at [`LICENSE.md`](LICENSE.md).

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance78

Regular maintenance activity

Popularity38

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~78 days

Recently: every ~32 days

Total

24

Last Release

160d ago

Major Versions

2.0.5 → 3.0.02023-06-23

3.0.7 → 4.0.02024-12-03

4.0.0 → 5.0.02025-04-30

4.0.2 → 5.0.12025-08-02

4.0.3 → 5.0.22025-10-06

PHP version history (7 changes)1.0.0PHP ^7.1.3 || ^8.0.0

2.0.0PHP ^7.4.0 || ^8.0.0

2.0.2PHP ^7.4.7 || ^8.0.0

2.0.3PHP ^7.4.3 || ^8.0.0

3.0.0PHP ^8.1.0

3.0.6PHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0

4.0.0PHP ~8.3.0 || ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5fea77dd303122241a6caac15ea7456607bcb6f5db869fc8fc9eaf3ec0630a84?d=identicon)[mimmi20](/maintainers/mimmi20)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (394 commits)")[![mimmi20](https://avatars.githubusercontent.com/u/1120192?v=4)](https://github.com/mimmi20 "mimmi20 (290 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (152 commits)")[![rodrigoprimo](https://avatars.githubusercontent.com/u/77215?v=4)](https://github.com/rodrigoprimo "rodrigoprimo (1 commits)")

---

Tags

mezziomezzio-authorizationphp83psr-7middlewarepsr-15authorizationmezzio

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mimmi20-mezzio-generic-authorization/health.svg)

```
[![Health](https://phpackages.com/badges/mimmi20-mezzio-generic-authorization/health.svg)](https://phpackages.com/packages/mimmi20-mezzio-generic-authorization)
```

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[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)[mezzio/mezzio-cors

CORS component for Mezzio and other PSR-15 middleware runners.

17568.5k5](/packages/mezzio-mezzio-cors)[middlewares/utils

Common utils for PSR-15 middleware packages

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

Router subcomponent for Mezzio

265.0M61](/packages/mezzio-mezzio-router)

PHPackages © 2026

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