t4web / authentication
A generic user authentication module for ZF2.
Requires
- php: ^5.5 || ^7.0
- t4web/event-subscriber: ~1.0.0
- t4web/session: ^1.0
- zendframework/zend-authentication: ~2.5.0
- zendframework/zend-console: ~2.5.0
- zendframework/zend-eventmanager: ~2.5.0
- zendframework/zend-http: ~2.5.0
- zendframework/zend-modulemanager: ~2.5.0
- zendframework/zend-mvc: ~2.5.0
- zendframework/zend-servicemanager: ~2.5.0
- zendframework/zend-session: ~2.5.0
- zendframework/zend-view: ~2.5.0
Requires (Dev)
- phpunit/phpunit: ^4.8
- squizlabs/php_codesniffer: ^2.3
README
Authentication module for zf2
Contents
Introduction
Very simple authentication from the Box - define accounts config with login and password and use.
Installation
Main Setup
By cloning project
Clone this project into your ./vendor/
directory.
With composer
Add this project in your composer.json:
"require": { "t4web/authentication": "~1.0.0" }
Now tell composer to download Authentication by running the command:
$ php composer.phar update
Post installation
Enabling it in your application.config.php
file.
<?php return array( 'modules' => array( // ... 'T4web\Authentication', ), // ... );
Configuring
For define which page need authorization, you can redeclare need-authorization-callback
, by default:
'need-authorization-callback' => function(RouteMatch $match) { $name = $match->getMatchedRouteName(); if ($name == 'auth-login') { return false; } if (strpos($name, 'admin') !== false) { return true; } return false; },
For change auth login form layout you can define layout
route param, for change
redirect uri after success authorization, you can define redirect-to-url
route param:
'router' => array( 'routes' => array( 'auth-login' => array( 'options' => array( 'defaults' => array( 'layout' => 'layout/my_auth_layout', 'redirect-to-url' => '/some/uri', ), ), ), ), ),
By default auth use php array for auth storage, but you can write own:
'service_manager' => [ 'factories' => [ Zend\Authentication\Adapter\AdapterInterface::class => Adapter\MyAdapter::class, ] ]
Adapter\MyAdapter
must implement Zend\Authentication\Adapter\ValidatableAdapterInterface
.
Adapters
This module contain two adapters in the Box PhpArray
and Table
.
PhpArray adapter
This adapter use by default.
For define logins and passwords just describe it in you config in auth-accounts
section:
'auth-accounts' => [ 'someUser1' => 'str0ngp@ssw0rd', 'someUser2' => '111', ],
Table adapter
This is wrapper for Zend\Authentication\Adapter\DbTable\CallbackCheckAdapter
, for start use, define it in your config:
'service_manager' => [ 'factories' => [ Zend\Authentication\Adapter\AdapterInterface::class => \T4web\Authentication\Adapter\TableFactory::class, ] ],
and describe auth['table-adapter']
config:
'auth' => [ 'table-adapter' => [ 'table-name' => 'users', 'identity-column' => 'email', 'credential-column' => 'password', ], ],
Testing
Unit test runnig from authentication module directory.
$ codeception run unit
For running Functional tests you need create codeception.yml in you project root, like this:
include: - vendor/t4web/authentication # <- add authentication module tests to include paths: log: tests/_output settings: colors: true memory_limit: 1024M
After this you may run functional tests from your project root
$ codeception run