定制 3cplus/auth-middleware 二次开发

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

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

3cplus/auth-middleware

最新稳定版本:1.0.0

Composer 安装命令:

composer require 3cplus/auth-middleware

包简介

3C plus - api auth middleware

README 文档

README

A PHP middleware for authentication using API tokens, with Redis caching support.

Installation

composer require 3cplus/auth-middleware

Description

This middleware authenticates requests by validating API tokens against a remote authentication service. It supports token extraction from both query parameters and Authorization headers. For performance optimization, authenticated user data is cached in Redis.

Requirements

  • PHP 7.2 or higher
  • Laravel/Illuminate Support
  • GuzzleHTTP
  • Predis

Environment Variables

The following environment variables are required:

Variable Description
URL_APPLICATION_API URL of the authentication API endpoint
REDIS_CACHE_HOST Redis server hostname
REDIS_CACHE_PORT Redis server port

Usage

Basic Implementation

use Dev3CPlus\Middleware\AuthMiddleware;

// Create middleware instance
$authMiddleware = new AuthMiddleware();

// Process the request
$response = $authMiddleware->process($request, $handler);

Token Extraction

The middleware extracts the API token in the following order:

  1. From query parameter: ?api_token=your-token
  2. From Authorization header: Authorization: Bearer your-token

Error Handling

The middleware throws exceptions with appropriate HTTP status codes:

  • 401 Unauthorized: When the API token is missing or invalid
  • 500 Internal Server Error: For other processing errors

Caching

Successfully authenticated user data is cached in Redis for 1 hour (3600 seconds) to minimize API calls.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-17