ez-php / auth
Authentication module for the ez-php framework — session and token-based auth with a flexible user provider interface
0.2.0
2026-03-15 03:47 UTC
Requires
- php: ^8.5
- ez-php/framework: 0.*
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13.0
README
Authentication module for the ez-php framework — session and token-based auth with a flexible user provider interface.
Requirements
- PHP 8.5+
- ez-php/framework ^1.0
Installation
composer require ez-php/auth
Setup
Register the service provider in your application:
$app->register(\EzPhp\Auth\AuthServiceProvider::class);
Implement UserProviderInterface to connect your user storage:
use EzPhp\Auth\UserProviderInterface; class UserProvider implements UserProviderInterface { public function findById(int|string $id): ?object { ... } public function findByCredentials(array $credentials): ?object { ... } public function validateCredentials(object $user, array $credentials): bool { ... } }
Then bind your provider in a service provider:
$this->app->bind(UserProviderInterface::class, UserProvider::class);
Usage
$auth = $app->make(\EzPhp\Auth\Auth::class); // Authenticate if ($auth->attempt(['email' => $email, 'password' => $password])) { $user = $auth->user(); } // Protect routes with middleware $router->get('/dashboard', $handler)->middleware(\EzPhp\Auth\Middleware\AuthMiddleware::class);
License
MIT — Andreas Uretschnig