Here is an example for the factory:
namespace User\Authentication;
use Laminas\Authentication\Adapter\DbTable\CallbackCheckAdapter;
use Laminas\Authentication\AuthenticationService;
use Laminas\Db\Adapter\Adapter;
use Laminas\Db\Adapter\AdapterInterface;
use Psr\Container\ContainerInterface;
use Webmozart\Assert\Assert;
final class AuthenticationServiceFactory
{
public function __invoke(
ContainerInterface $container
): AuthenticationService {
$databaseAdapter = $container->get(AdapterInterface::class);
Assert::isInstanceOf($databaseAdapter, Adapter::class);
$credentialValidationCallback =
static function (
string $dbCredential,
string $requestCredential
): bool {
return password_verify($requestCredential, $dbCredential);
};
$authAdapter = new CallbackCheckAdapter(
$databaseAdapter,
'user', // table name
'email', // identity column
'password', // credential column
$credentialValidationCallback
);
return new AuthenticationService(null, $authAdapter);
}
}