Username/password, session-backed authentication adapter for zend-expressive-authentication.
This library provides a zend-expressive-authentication adapter that handles form-based username/password authentication credentials where the user details are subsequently stored in a session.
Run the following to install this library:
$ composer require zendframework/zend-expressive-authentication-session
You will need to provide configuration for this module to work correctly. The following demonstrates:
- Mapping a custom
UserRepositoryInterfaceimplementation for use as a backend to the functionality this authentication adapter provides.
- Mapping the
PhpSessionadapter as the
AuthenticationInterfaceimplementation to use in your application.
- Providing configuration for this adapter, including custom field names for the username and password, as well as a path in the application to which to redirect when no valid credentials are present.
<?php // in a config/autoload/*.global.php file: declare(strict_types=1); //use App\Infrastructure\Repository\UserRepository; //use App\Infrastructure\Repository\UserRepositoryFactory; use Zend\Expressive\Authentication\AuthenticationInterface; use Zend\Expressive\Authentication\Session\PhpSession; use Zend\Expressive\Authentication\UserRepositoryInterface; return [ 'dependencies' => [ 'aliases' => [ AuthenticationInterface::class => PhpSession::class, UserRepositoryInterface::class => UserRepository::class, ], 'factories' => [ UserRepository::class => UserRepositoryFactory::class, ], ], 'authentication' => [ 'username' => null, // provide a custom field name for the username 'password' => null, // provide a custom field name for the password 'redirect' => '/login', // URI to which to redirect if no valid credentials present ], ];
$ mkdocs build
You may also browse the documentation online.