PHPackages                             aist/authentication-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. aist/authentication-middleware

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

aist/authentication-middleware
==============================

PSR-7 Authentication Middleware

034PHP

Since Jan 17Pushed 8y ago1 watchersCompare

[ Source](https://github.com/ma-si/authentication-middleware)[ Packagist](https://packagist.org/packages/aist/authentication-middleware)[ RSS](/packages/aist-authentication-middleware/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Authentication Middleware [![SensioLabsInsight](https://camo.githubusercontent.com/b239e2be0ee85fd80e0a524a42fc54b397edee2180c4f7eb419be125caf7433a/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f63653033623233372d313039302d343565642d383462302d3537663334363531636237392f736d616c6c2e706e67)](https://insight.sensiolabs.com/projects/ce03b237-1090-45ed-84b0-57f34651cb79)
================================================================================================================================================================================================================================================================================================================================================================================================================

[](#authentication-middleware-)

[![Build status](https://camo.githubusercontent.com/e6d146cfa5baf28cda950a340aa61fc44632ffb9c2a446e718263a557e82927f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d612d73692f61757468656e7469636174696f6e2d6d6964646c65776172652f6d61737465722e7376673f7374796c653d666c61742d737175617265266c6162656c3d6d6173746572)](https://secure.travis-ci.org/ma-si/authentication-middleware)[![Coverage Status](https://camo.githubusercontent.com/ef6166af16c08388703d7b41402d8239034e83ba20385764e30cabf7bb87f106/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6d612d73692f61757468656e7469636174696f6e2d6d6964646c65776172652f6d61737465722e7376673f7374796c653d666c61742d737175617265266c6162656c3d6d6173746572254332254130636f766572616765)](https://coveralls.io/r/ma-si/authentication-middleware?branch=master)[![Code Climate](https://camo.githubusercontent.com/0b765017e09422a2686215bef6facd609e402397de7665c8cc6909dd5a4a2cb7/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6769746875622f6d612d73692f61757468656e7469636174696f6e2d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/ma-si/authentication-middleware)[![Sensio](https://camo.githubusercontent.com/41b76583460095d9ff5c20d03883842d25d7b0669b34c6b6bac522a383eda213/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f63333434626235642d396436362d346636332d623030362d6234643735383634333930342e7376673f7374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/c344bb5d-9d66-4f63-b006-b4d758643904)[![Packagist](https://camo.githubusercontent.com/ba406810e8ebf413108e12a9efeaf2630e096fc175fdcfd4bc91cbd837a8be1b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616973742f61757468656e7469636174696f6e2d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aist/authentication-middleware)

[![Minimum PHP Version](https://camo.githubusercontent.com/90eed33e7df559b70b174e97d37a4907946803c7ab691640166d2518d8cd2118/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e302d3838393242462e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![License](https://camo.githubusercontent.com/620daf907e5265b8c87cd9b2b9bb157caed0aa648490eb57014f21ea5bb8ae3e/68747470733a2f2f706f7365722e707567782e6f72672f616973742f61757468656e7469636174696f6e2d6d6964646c65776172652f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://opensource.org/licenses/BSD-3-Clause)

*PSR-7 Authentication Middleware.*

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

[](#installation)

Install via composer:

```
$ composer require aist/authentication-middleware
```

Configuration
-------------

[](#configuration)

### Add configuration file

[](#add-configuration-file)

copy authentication-middleware.global.php.dist to authentication-middleware.global.php

```
// authentication-middleware.global.php.dist
return [
    'authentication-middleware' => [
        'identity_key' => 'identity',
        'default_redirect_route' => 'login',
        'success_redirect_route' => 'home',
        'success_role_redirect_route' => [
            'admin' => 'admin/dashboard',
            'user' => 'home',
        ],
        'whitelist' => [
            'login',
            'logout',
        ],
    ],
];
```

### Register your own authentication adapter

[](#register-your-own-authentication-adapter)

by invokables

```
'invokables' => [
    'authentication.adapter' => \App\Authentication\Adapter\YourAdapter::class,
],
```

or by factories

```
'factories' => [
    'authentication.adapter' => \App\Authentication\Adapter\YourAdapterFactory::class,
],
```

### Register your own login action

[](#register-your-own-login-action)

```
'factories'  => [
    \Aist\AuthenticationMiddleware\Action\LoginAction::class => LoginFactory::class,
],
```

### Register your own login form

[](#register-your-own-login-form)

```
'form_elements' => [
    'factories'  => [
        'Aist\AuthenticationMiddleware\Form\LoginForm' => \App\Form\LoginCompanyFormFactory::class,
    ],
],
```

### Add pipe

[](#add-pipe)

to protect whole app

```
// Add more middleware here that needs to introspect the routing results; this
// might include:
//
// - route-based authentication
// - route-based validation
// - etc.

// Authentication middleware
$app->pipe(\Aist\AuthenticationMiddleware\Middleware\AuthenticationMiddleware::class);

// Permission middleware
// At this point, if no identity is set by authentication middleware, the
// UnauthorizedHandler kicks in; alternately, you can provide other fallback
// middleware to execute.
//$app->pipe(\Aist\AuthorizationMiddleware\Middleware\UnauthorizedHandler::class);
// Authorization
$app->pipe(\Aist\AuthorizationMiddleware\Middleware\AuthorizationMiddleware::class);
```

or use for specific route

```
$app->get(
    '/',
    [
        \Aist\AuthenticationMiddleware\Middleware\AuthenticationMiddleware::class,
        \Aist\AuthorizationMiddleware\Middleware\AuthorizationMiddleware::class,
        App\Action\DashboardAction::class,
    ],
    'dashboard'
);
```

### Add authentication routes

[](#add-authentication-routes)

```
$app->route('/login', \Aist\AuthenticationMiddleware\Action\LoginAction::class, ['GET', 'POST'], 'login');
$app->get('/logout', Aist\AuthenticationMiddleware\Action\LogoutAction::class, 'logout');
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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/42b693076307a5fa17b0df69ee058c3f95482bd01e93f3d17a27137d6fdf1c17?d=identicon)[aist](/maintainers/aist)

---

Top Contributors

[![ma-si](https://avatars.githubusercontent.com/u/1869327?v=4)](https://github.com/ma-si "ma-si (2 commits)")

### Embed Badge

![Health badge](/badges/aist-authentication-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/aist-authentication-middleware/health.svg)](https://phpackages.com/packages/aist-authentication-middleware)
```

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

761.2M17](/packages/kartik-v-yii2-password)

PHPackages © 2026

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