plopster/jwt-auth
最新稳定版本:v0.0.1
Composer 安装命令:
composer require plopster/jwt-auth
包简介
Library for standard jwt validation and generation
README 文档
README
A modular and extensible JWT authentication library built on top of firebase/php-jwt.
It provides a clean structure for generating, validating, refreshing, and customizing tokens with support for custom payloads and claim validation.
Installation
composer require yourname/jwt-auth
Usage Example
use JwtAuth\Config\JwtConfig; use JwtAuth\Claims\DefaultClaimsProvider; use JwtAuth\Keys\LocalKeyProvider; use JwtAuth\Services\TokenGenerator; use JwtAuth\Services\TokenValidator; use JwtAuth\Services\TokenRefresher; use JwtAuth\Validation\DefaultClaimValidator; use JwtAuth\Core\JwtManager; $config = new JwtConfig( issuer: 'my-app', audience: 'my-users', algorithm: 'RS256', privateKeyPath: __DIR__ . '/keys/private.pem', publicKeyPath: __DIR__ . '/keys/public.pem', ttl: 3600 ); $keyProvider = new LocalKeyProvider($config->privateKeyPath, $config->publicKeyPath); $claimsProvider = new DefaultClaimsProvider($config->issuer, $config->audience, $config->ttl); $claimValidator = new DefaultClaimValidator(); $generator = new TokenGenerator($config, $claimsProvider, $keyProvider); $validator = new TokenValidator($config, $keyProvider); $refresher = new TokenRefresher($generator); $jwtManager = new JwtManager($generator, $validator); // Generate a token $token = $jwtManager->createToken(['user_id' => 42]); // Validate the token $payload = $jwtManager->verifyToken($token); // Refresh the token $newToken = $refresher->refresh($payload);
Features
-
Generate JWT tokens with default or custom claims
-
Validate tokens and decode payloads securely
-
Refresh tokens using existing payload data
-
Extend or replace any component:
ClaimsProviderInterfacefor custom payload logicClaimValidatorInterfacefor custom validation rulesTokenPayloadInterfacefor custom payload objectsKeyProviderInterfacefor flexible key management (file, env, KMS, etc.)
Project Structure
src/
├── Claims/
├── Config/
├── Contracts/
├── Core/
├── Exceptions/
├── Keys/
├── Services/
└── Validation/
Each folder is modular and follows the single-responsibility principle, making the library scalable and easy to maintain.
License
Proprietary License.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2025-10-25