Download the PHP package tinywan/jwt without Composer
On this page you can find all versions of the php package tinywan/jwt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package jwt
π JSON Web Token (JWT) for Webman
δΈζθ―΄ζ
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This token is designed to be compact and secure, making it particularly suitable for Single Sign-On (SSO) scenarios in distributed applications.
Note: Starting from version
1.14.0, secret key length validation has been introduced for security reasons. Versions prior to1.14.0did not strictly check key lengths; versions1.14.0and above enforce minimum key length requirements.
v2.0.0 Upgrade Guide
v2.0.0 raises the minimum PHP requirement to PHP 8.2+ and drops support for PHP 7.4, 8.0, and 8.1.
- Projects running older PHP versions should stay on
v1.15.x. - Projects on PHP 8.2+ can upgrade using:
Installation
Install via Composer:
Quick Start
Generating a Token
Output (JSON format):
Response Parameters:
| Parameter | Type | Description | Example |
|---|---|---|---|
token_type |
string | Token type | Bearer |
expires_in |
int | Token expiration duration (seconds) | 36000 |
access_token |
string | Access token | XXXXXXXXXXXXXXXXXXXX |
refresh_token |
string | Refresh token (used to renew expired access tokens) | XXXXXXXXXXXXXXXXXXXX |
Supported Methods & APIs
1. Get Current User ID
2. Get All Payload Claims (Custom Fields)
3. Get Specific Claim Value
4. Refresh Token (Exchange Refresh Token for New Access Token)
5. Get Remaining Token Lifetime
6. Single Device Login (SSO)
Disabled by default. To enable, update your configuration file config/plugin/tinywan/jwt/app.php:
Single device login supports defining the client type
client(defaults toWEB), such as:MOBILE,APP,WEB,ADMIN,API,OTHER, etc.
7. Get Current User Model (>= 1.2.4)
The 'user_model' configuration option accepts a closure (defaults to returning an empty array). You can customize the return model based on your ORM:
ThinkORM Configuration:
Laravel ORM (Illuminate Database) Configuration:
8. Clear Token (Logout)
Only takes effect when
is_single_deviceis set totrue. Supported parameters:MOBILE,APP,WEB,ADMIN,API,OTHER, etc.
9. Custom Client Types
Defaults to WEB.
10. Custom Expiration Time for Access & Refresh Tokens
11. Minimum Key Length Requirements (>= 1.14.0)
Mandatory minimum key length requirements (especially for HS* symmetric algorithms):
| Algorithm | Minimum Key Length (Bytes) | Reference Character Count (UTF-8) | Recommended Generation Method |
|---|---|---|---|
| HS256 | 32 bytes | β₯ 32 characters | bin2hex(random_bytes(32)) β 64 hex chars |
| HS384 | 48 bytes | β₯ 48 characters | random_bytes(48) |
| HS512 | 64 bytes | β₯ 64 characters | random_bytes(64) |
12. Token Error Codes
- Access Token Errors:
- Invalid authentication token:
401011 - Authentication token not active yet:
401012 - Session expired, please log in again:
401013 - Requested custom claim does not exist:
401014 - Unknown access token error:
401015
- Invalid authentication token:
- Refresh Token Errors:
- Invalid refresh token:
401021 - Refresh token not active yet:
401022 - Refresh token session expired, please log in again:
401023 - Requested refresh token custom claim does not exist:
401024 - Unknown refresh token error:
401025
- Invalid refresh token:
Signature Algorithms (JWA)
Common signature algorithms include: HS256 (HMAC-SHA256), RS256 (RSA-SHA256), and ES256 (ECDSA-SHA256).
Supported Algorithms List
Note: Only
RS256andES256are marked as Recommended.
Symmetric Algorithms
Defaults to HS256 symmetric encryption.
HS256 uses the same secret_key for signing and verification. If the secret key leaks, security is completely compromised. Therefore, HS256 is best suited for centralized authentication where signing and validation are both performed by trusted parties.
Asymmetric Algorithms
RS256 uses an RSA private key for signing and an RSA public key for verification.
Public key exposure causes no security risk as long as the private key remains secure. RS256 allows delegating verification to third-party services by simply providing them the public key.
Key Pair Generation Commands (OpenSSL)
RS512:
RS384:
RS256:
π Video Tutorials
- How to use the JWT Authentication Plugin: https://www.bilibili.com/video/BV1HS4y1F7Jx
- How to use the JWT Authentication Plugin (Algorithms Guide): https://www.bilibili.com/video/BV14L4y1g7sY
Security & Flow
Concepts
Authentication and authorization are critical yet complex topics in software engineering. In many frameworks, handling security accounts for a significant portion of code. JWT helps you handle authentication easily, securely, and in a standardized way without having to reinvent security specifications.
Flow Scenario
Suppose your backend API lives on one domain, and your frontend (SPA or mobile application) lives on another domain. When a user submits credentials (username & password), the API validates them and responds with an access token. The frontend includes this token in the Authorization header (Bearer <token>) on subsequent requests.
Authentication & Authorization Flowchart

Token Signing Process
- User sends username and password to the authentication server.
- The authentication server verifies credentials and generates a JWT Token:
- Encodes JWT Header and Payload with Base64URL.
- Signs the token:
HMAC-SHA256(SecretKey, Base64UrlEncode(Header) + "." + Base64UrlEncode(Payload)).
- Returns
base64(header).base64(payload).signatureas the token to the client. - Client attaches the token in request headers for subsequent protected API calls.
License
This project is open-sourced software licensed under the Apache-2.0 License.
All versions of jwt with dependencies
ext-json Version *
workerman/webman-framework Version ^1.2.1||^2.0
firebase/php-jwt Version ^6.8||^7.0