byjg/jwt-wrapper
Composer 安装命令:
composer require byjg/jwt-wrapper
包简介
A simple and flexible wrapper around the Firebase JWT library that makes JWT token handling easy and intuitive in PHP applications
README 文档
README
| sidebar_key | jwt-wrapper | |||
|---|---|---|---|---|
| tags |
|
JWT Wrapper
A simple and flexible wrapper around the Firebase JWT library that makes JWT token handling easy and intuitive in PHP applications.
Features
- Simple API: Create and validate JWT tokens with minimal code
- Flexible Signing: Support for both HMAC (shared secret) and RSA/ECDSA (public/private key) methods
- Automatic Claims: Built-in handling of standard JWT claims (iat, exp, nbf)
- HTTP Integration: Helper methods for extracting tokens from HTTP headers
- Key Management: Intuitive interfaces for different key types
Installation
composer require "byjg/jwt-wrapper"
Quick Example
// Create a JWT token using HMAC $server = "example.com"; $secret = new \ByJG\JwtWrapper\JwtHashHmacSecret(base64_encode("your_secret_key")); $jwtWrapper = new \ByJG\JwtWrapper\JwtWrapper($server, $secret); // Add custom data and set expiration $token = $jwtWrapper->generateToken( $jwtWrapper->createJwtData(["userId" => 123], 3600) ); // Validate and extract data try { $jwtData = $jwtWrapper->extractData($token); $userId = $jwtData->data->userId; } catch (\ByJG\JwtWrapper\JwtWrapperException $e) { // Handle invalid token }
Documentation
Detailed documentation:
| Document | Description |
|---|---|
| Overview | Introduction and core concepts |
| Key Types | HMAC and OpenSSL key configuration |
| Creating Tokens | Token generation and customization |
| Validating Tokens | Token validation and data extraction |
| API Reference | Complete class and method documentation |
Examples
The library includes complete examples in the example directory showing:
- Token creation with login.php
- Token validation with api.php
- Client-side usage with client.html
sequenceDiagram
participant LOCAL
participant CLIENT
participant SERVER
participant PRIVATE_RESOURCE
LOCAL->>CLIENT: Retrieve Local Token
CLIENT->>SERVER: Pass Token
SERVER->>PRIVATE_RESOURCE: Validate Token
PRIVATE_RESOURCE->>CLIENT: Return Result if token is valid
CLIENT->>LOCAL: Store Token
Loading
Running the tests
vendor/bin/phpunit
Dependencies
flowchart TD
byjg/jwt-wrapper --> firebase/php-jwt
byjg/jwt-wrapper --> ext-openssl
Loading
byjg/jwt-wrapper 适用场景与选型建议
byjg/jwt-wrapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 105.19k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2017 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 byjg/jwt-wrapper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 byjg/jwt-wrapper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 105.19k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 30
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-02-08