2017 © Pedro Peláez
 

library authentication-middleware

PSR-7 Authentication Middleware

image

aist/authentication-middleware

PSR-7 Authentication Middleware

  • Wednesday, January 17, 2018
  • by aist
  • Repository
  • 1 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Authentication Middleware SensioLabsInsight

Build status ![Coverage Status][Master coverage image] ![Code Climate][Code Climate image] ![Sensio][SensioLabsInsight image] ![Packagist][Packagist image], (*1)

![Minimum PHP Version][Minimum PHP Version image] ![License][License image], (*2)

PSR-7 Authentication Middleware., (*3)

Installation

Install via composer:, (*4)

$ composer require aist/authentication-middleware

Configuration

Add configuration file

copy authentication-middleware.global.php.dist to authentication-middleware.global.php, (*5)

// 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

by invokables, (*6)

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

or by factories, (*7)

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

Register your own login action

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

Register your own login form

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

Add pipe

to protect whole app, (*8)

// 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, (*9)

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

Add authentication routes

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

The Versions