定制 michel/michel-auth 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

michel/michel-auth

Composer 安装命令:

composer require michel/michel-auth

包简介

A PSR-15 compliant authentication library providing form and token-based authentication handlers.

README 文档

README

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.

Features

  • PSR-15 Middleware: Seamlessly integrates into any modern PHP framework or application that supports PSR-15 middleware (AuthMiddleware).
  • Multiple Handlers:
    • 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).
  • Customizable: Implements UserProviderInterface to easily plug in your own user storage (database, memory, external APIs).
  • Security: Built-in interfaces (PasswordAuthenticatedUserInterface) for secure password checking and automatic password upgrades.
  • Error Handling: Easily catch and handle authentication failures gracefully with custom callbacks (onFailure).

Installation

You can install the library via Composer:

composer require michel/michel-auth

Basic Usage

1. Implement User and Provider Interfaces

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.

2. Form Authentication

Set up form authentication for your web application.

use Michel\Auth\Handler\Authentication\UserFormAuthHandler;use Michel\Auth\Middlewares\Authentication\AuthMiddleware;

// $userProvider = new YourUserProvider();
// $sessionStorage = new YourSessionStorage();

$formHandler = new UserFormAuthHandler($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

3. Token Authentication (API)

Ideal for stateless APIs using header tokens.

use Michel\Auth\Handler\Authentication\UserTokenAuthHandler;use Michel\Auth\Middlewares\Authentication\AuthMiddleware;

$tokenHandler = new UserTokenAuthHandler($userProvider, 'Authorization');

$authMiddleware = new AuthMiddleware($tokenHandler, $responseFactory, $logger);
// Add $authMiddleware to your API routes

License

This project is licensed under the MPL-2.0 License. See the LICENSE file for details.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MPL-2.0
  • 更新时间: 2026-03-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固