zen0x7/tokenizer
最新稳定版本:1.0.2
Composer 安装命令:
composer require zen0x7/tokenizer
包简介
PHP SDK for Service Framework authentication and token generation.
README 文档
README
A high-performance PHP SDK for generating authenticated and encrypted JSON Web Tokens (JWT) for the Service Framework cluster.
Features
- JWE/JWS Support: Fully compatible with the C++ implementation (AES-256-GCM + HMAC-SHA256).
- Fluent Builder: Easy token construction with a human-readable interface.
- Grants & Wildcards: Full support for resource-based grants (
channels:*,cache:user.*,system:admin). - Laravel Ready: Easily integrable into any PHP 8.1+ project or framework.
Installation
Install via Composer:
composer require zen0x7/tokenizer
Usage
Generating a Token
use Zen0x7\Tokenizer\TokenBuilder; $builder = TokenBuilder::create() ->withSubject('user_123') ->withDuration(3600) // 1 hour ->withSystemPermissions(['admin', 'broadcast']) ->withChannelPermissions('chat.general', ['read', 'write']) ->withChannelPermissions('private.*', ['read']) ->withCachePermissions('user:profile:*', ['read', 'write', 'delete']) ->withClaim('custom_field', 'custom_value'); $token = $builder->build( signatureKey: 'base64:your_signature_key_here', encryptionKey: 'base64:your_encryption_key_here' ); echo "Authorization: Bearer " . $token;
Key Formats
The SDK supports both raw binary keys and base64-encoded keys (prefixed with base64:).
// Example with base64 keys $signatureKey = 'base64:c2VjcmV0X3NpZ25hdHVyZV9rZXlfZm9yX2V4YW1wbGVfdXNhZ2U='; $encryptionKey = 'base64:YWVzXzI1Nl9nY21fZXhhbXBsZV9rZXlfMzJfYnl0ZXM=';
Security
This SDK implements:
- JWS (JSON Web Signature): HMAC-SHA256 protecting the entire token.
- JWE (JSON Web Encryption): AES-256-GCM encrypting the payload.
- Base64Url: Standard URL-safe encoding for JWT parts.
License
MIT
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-27