Tutorial
In This Article
Configuration
You will need to provide configuration for the adapter to work correctly:
-
You will need to alias the zend-expressive-authentication
AuthenticationInterfaceto the package'sPhpSessionimplementation. -
You will need to ensure a zend-expressive-authentication
UserRepositoryInterfaceimplementation is available and configured. -
You will need to provide a factory capable of generating a
UserInterfaceinstance, if you do not want to use the default provided by zend-expressive-authentication. -
You will need to provide a URL or path to which the authentication middleware will redirect if no user is discovered in the session.
Example
Below is an example demonstrating authentication configuration you might provide when using zend-expressive-authentication-session. In particular:
-
It aliases the
PdoDatabaseuser repository implementation from zend-expressive-authentication as theUserRepositoryInterfaceservice. -
It aliases the
PhpSessionadapter from this package to theAuthenticationInterfaceservice. -
It does not configure a
Zend\Expressive\Authentication\UserInterfaceservice, opting to use the default provided by zend-expressive-authentication. -
It configures the path
/loginas the URL to which unauthenticated users will be redirected.
// in a config/autoload/*.global.php file:
declare(strict_types=1);
use Zend\Expressive\Authentication\AuthenticationInterface;
use Zend\Expressive\Authentication\Session\PhpSession;
use Zend\Expressive\Authentication\UserRepositoryInterface;
use Zend\Expressive\Authentication\UserRepository\PdoDatabase;
return [
'dependencies' => [
'aliases' => [
AuthenticationInterface::class => PhpSession::class,
UserRepositoryInterface::class => PdoDatabase::class,
],
],
'authentication' => [
'redirect' => '/login',
],
];
Handling the login
Once you have configured the adapter, you will also need to write a handler that will handle login attempts.
Found a mistake or want to contribute to the documentation? Edit this page on GitHub!