Download the PHP package vaibhavpandeyvpz/jweety without Composer
On this page you can find all versions of the php package vaibhavpandeyvpz/jweety. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vaibhavpandeyvpz/jweety
More information about vaibhavpandeyvpz/jweety
Files in vaibhavpandeyvpz/jweety
Package jweety
Short Description Simple JWT (RFC 7519) encoding/decoding and validation library, for PHP >= 8.2.
License MIT
Homepage https://github.com/vaibhavpandeyvpz/jweety
Informations about the package jweety
jweety
A simple, modern JWT (RFC 7519) encoding/decoding and validation library for PHP 8.2+.
Features
- ✅ RFC 7519 Compliant - Full support for JSON Web Token standard
- ✅ Modern PHP 8.2+ - Uses latest PHP features (enums, readonly properties, match expressions)
- ✅ HMAC Algorithms - Supports HS256, HS384, and HS512
- ✅ Type Safe - Comprehensive type hints and strict types
- ✅ Claim Validation - Automatic validation of
exp,iat, andnbfclaims - ✅ PSR-20 Clock Support - Use any PSR-20 clock implementation for testable time-based validation
- ✅ Exception Handling - Specific exception types for different error scenarios
- ✅ 100% Test Coverage - Fully tested with comprehensive test suite
Installation
Install via Composer:
Quick Start
Creating a Token
Parsing and Validating a Token
Parsing Without Claim Validation
Usage Examples
Using Different Algorithms
Restricting Allowed Algorithms
Using PSR-20 Clock for Testing
The library supports PSR-20 Clock implementations for controllable time in tests:
Custom Token Type
Manual Claim Validation
Working with Standard JWT Claims
API Reference
Encoder Class
Constructor
$key- Secret key for HMAC signing (marked as sensitive)$algorithms- Allowed algorithms (defaults to all supported)$clock- Optional PSR-20 Clock implementation for time-based claim validation. If not provided, uses system time viatime(). Useful for testing with controllable time.
Methods
stringify()
Creates a JWT token from claims.
Parameters:
$claims- Claims to encode (array or object)$alg- Algorithm to use (enum or string)$typ- Token type (defaults to 'JWT')
Returns: JWT token string
Throws: UnsupportedAlgorithmException if algorithm is not allowed/supported
parse()
Parses and validates a JWT token.
Parameters:
$token- JWT token string$assert- Whether to validate claims (defaults to true)
Returns: Decoded claims object
Throws:
InvalidTokenException- Token is malformed or invalidInvalidSignatureException- Signature verification failedTokenExpiredException- Token has expired (if$assertis true)
assert()
Validates JWT claims.
Parameters:
$claims- Claims object to validate
Throws:
TokenExpiredException- Token expiredInvalidTokenException- Invalid claims (iat in future, nbf not met)
encode() / decode()
Static utility methods for base64url encoding/decoding.
Algorithm Enum
Exception Handling
The library provides specific exception types for different error scenarios:
InvalidTokenException- Token is malformed, invalid encoding, or has invalid claimsTokenExpiredException- Token has expired (exp claim)InvalidSignatureException- Signature verification failedUnsupportedAlgorithmException- Algorithm is not allowed or not supported
All exceptions extend standard PHP exceptions, so you can catch them specifically or use a general exception handler.
Security Considerations
- Secret Key Management: Always use strong, randomly generated secret keys
- Key Storage: Never commit secret keys to version control
- HTTPS: Always transmit tokens over HTTPS
- Algorithm Restriction: Restrict allowed algorithms to only what you need
- Token Expiration: Always set appropriate expiration times
- Sensitive Data: Don't store sensitive information in token payload (it's base64 encoded, not encrypted)
Requirements
- PHP >= 8.2
- Composer (for installation)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues, questions, or contributions, please visit the GitHub repository.