A PSR-15 compliant authentication library providing form and token-based authentication handlers.
|
|
22 saat önce | |
|---|---|---|
| src | 22 saat önce | |
| .gitignore | 1 gün önce | |
| LICENSE | 1 gün önce | |
| README.md | 22 saat önce | |
| composer.json | 1 gün önce |
A flexible and lightweight PSR-15 compliant authentication library for PHP applications. This library provides a middleware-based approach to handle user authentication, supporting both traditional form-based logins and token-based API authentication.
AuthMiddleware).FormAuthHandler: For handling classical HTML form logins. Relies on michel/session to persist user sessions.TokenAuthHandler: For handling API authentications via HTTP headers (e.g., Bearer tokens, API keys).UserProviderInterface to easily plug in your own user storage (database, memory, external APIs).PasswordAuthenticatedUserInterface) for secure password checking and automatic password upgrades.onFailure).You can install the library via Composer:
composer require michel/michel-auth
First, create a user class that implements Michel\Auth\UserInterface (and optionally Michel\Auth\PasswordAuthenticatedUserInterface for form login).
Then, create a provider implementing Michel\Auth\UserProviderInterface to fetch these users.
Set up form authentication for your web application.
use Michel\Auth\Handler\FormAuthHandler;
use Michel\Auth\Middlewares\AuthMiddleware;
// $userProvider = new YourUserProvider();
// $sessionStorage = new YourSessionStorage();
$formHandler = new FormAuthHandler($userProvider, $sessionStorage, [
'login_path' => '/login',
'login_key' => 'email',
'password_key' => 'password',
]);
$authMiddleware = new AuthMiddleware($formHandler, $responseFactory, $logger);
// Add $authMiddleware to your PSR-15 compatible application router/dispatcher
Ideal for stateless APIs using header tokens.
use Michel\Auth\Handler\TokenAuthHandler;
use Michel\Auth\Middlewares\AuthMiddleware;
$tokenHandler = new TokenAuthHandler($userProvider, 'Authorization');
$authMiddleware = new AuthMiddleware($tokenHandler, $responseFactory, $logger);
// Add $authMiddleware to your API routes
This project is licensed under the MPL-2.0 License. See the LICENSE file for details.