A Python implementation of JSON Web Tokens (JWT) for authentication and authorization using a symmetric secret key and HMAC-SHA256.
Project description
JWT Authentication
A Python implementation of JSON Web Tokens (JWT) for authentication and authorization using a symmetric secret key and HMAC-SHA256.
Features
- Generate JWT tokens with customizable expiration times
- Validate JWT tokens and verify their integrity using a symmetric secret key and HMAC-SHA256
- Extract user information (such as user ID 'sub') from JWT tokens
Installation
You can install the package via pip:
pip install ft_jwt
Usage
from ft_jwt.ft_jwt import FT_JWT
# Create a JWT instance with your secret key
secret_key = 'your_secret_key'
ftjwt = FT_JWT(secret_key)
# Generate a token for a user
sub = '1'
token = jwt.createToken(sub)
# Validate a token
is_valid, message = ftjwt.validateToken(token)
if is_valid:
print('Token is valid')
else:
print(f'Token is invalid: {message}')
# Get the user ID from a token
user_id = ftjwt.getUserId(token)
print(f'User ID: {sub}')
# Use the decorator to validate against a JWT for a protected route
@ftjwt.token_required
def protected_route():
# This function will be executed only if the token is valid
# ...
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
License
This project is licensed under the MIT License.
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
ft_jwt-0.0.17.tar.gz
(3.5 kB
view details)
File details
Details for the file ft_jwt-0.0.17.tar.gz.
File metadata
- Download URL: ft_jwt-0.0.17.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2351e9989da4f15748dbb021b9b95f48f01006cadc5d0ef417e2b873df4e9494
|
|
| MD5 |
2dcec4423c76d0f100d75fcfcf3252c2
|
|
| BLAKE2b-256 |
298aa9f2f43e0950dd82b08b209128a6e1579152c00f03977550d5873135ac7f
|