JWT authentication library for Python
Project description
JWT Auth Modules - Python
A simple and secure JWT (JSON Web Token) authentication library for Python applications.
Features
- 🔐 Generate and validate JWT access tokens
- 🔄 Refresh token support
- ⚙️ Configurable token expiration
- 🛡️ Signature verification
- 📝 Custom claims support
- 🎯 Type-safe with full type hints
- ✅ Comprehensive test coverage
Installation
pip install jwt-auth-module
Quick Start
from jwt_auth import JwtConfig, JwtTokenGenerator, JwtTokenValidator
# Create configuration with your own secret key
config = (
JwtConfig.builder()
.secret_key("your-base64-encoded-secret-key")
.issuer("your-app-name")
.build()
)
# Generate tokens
generator = JwtTokenGenerator(config)
access_token = generator.generate_access_token("user123")
refresh_token = generator.generate_refresh_token("user123")
# Validate tokens
validator = JwtTokenValidator(config)
is_valid = validator.validate_token(access_token)
# Parse token claims
from jwt_auth import JwtTokenParser
parser = JwtTokenParser(config)
claims = parser.parse_token(access_token)
user_id = claims.get_subject()
Configuration
from jwt_auth import JwtConfig
# Using builder pattern (recommended)
config = (
JwtConfig.builder()
.secret_key("your-base64-encoded-secret-key")
.issuer("your-app-name")
.access_token_expiration_seconds(3600) # 1 hour
.refresh_token_expiration_seconds(604800) # 7 days
.build()
)
# Using defaults (for testing only)
config = JwtConfig.with_all_defaults()
⚠️ Security Warning: Never use the default secret key in production. Always provide your own secure secret key.
Custom Claims
# Add custom claims to tokens
custom_claims = {
"role": "admin",
"scope": "read:write",
"department": "engineering"
}
token = generator.generate_access_token("user123", custom_claims)
# Parse and access custom claims
claims = parser.parse_token(token)
role = claims.get_claim("role")
Requirements
- Python 3.9+
- PyJWT >= 2.8.0
License
MIT License
Related Projects
Contributing
Contributions are welcome! Please visit the GitHub repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jwt_auth_module-0.1.1.tar.gz.
File metadata
- Download URL: jwt_auth_module-0.1.1.tar.gz
- Upload date:
- Size: 23.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea471bc90bac301cadba17b13c0a947f5dc710ca6fbc7a8d7e06ee133d1624b6
|
|
| MD5 |
bb700ccb70ddfc8e72786361a4d9882b
|
|
| BLAKE2b-256 |
36afedb3ff288416e65f2e7402bf23101c85f22fbf7f218076673db6e4057e6a
|
File details
Details for the file jwt_auth_module-0.1.1-py3-none-any.whl.
File metadata
- Download URL: jwt_auth_module-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dfd1e114c0c6d10a8304c5cf1afa97c5a947ea261be60224ba3307c6bf5af23
|
|
| MD5 |
747ff5bced9d68ac33f2c40a3f5d70a2
|
|
| BLAKE2b-256 |
6de458d7f99080e55a6bbcfdbe6e17df75008d81a5166afd094dceabece8ff4a
|