Skip to content

t4web/Authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Authentication

Master: Build Status codecov.io Scrutinizer Code Quality

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.phpfile.

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