A professional-grade hybrid lightweight authentication and session management library.
Project description
Tokenly-Auth
Tokenly-Auth is a professional-grade Python library designed to handle Hybrid state authentication, session management, and security concerns for modern web applications. It provides a robust set of tools for password hashing, JWT management, rate limiting, and brute-force protection.
Core Features
- Secure Password Management: Uses Argon2 hashing with built-in brute-force protection and account locking.
- JWT Handling: Full support for access token generation, verification, and blacklisting.
- Session Persistence: Secure refresh token rotation and validation logic.
- Rate Limiting: Storage-agnostic rate limiting to prevent API abuse.
- Data Integrity: SQLModel-based schemas for easy integration with relational databases.
- Validation: Strict structural validation for user credentials.
Installation
Ensure you have the required dependencies installed:
pip install tokenly-auth
Quick Start
1. Database Setup
Tokenly-Auth uses SQLModel, allowing for easy database integration. You can use the provided DatabaseManager to initialize your database.
from tokenly_auth import DatabaseManager
db = DatabaseManager(db_url="sqlite:///./auth.db")
# Create tables (Run this during initial setup)
db.init_db()
# Get a session
with next(db.get_session()) as session:
# Use the session with Tokenly-Auth functions
pass
2. Password Hashing and Verification
from tokenly_auth import userdata, hash_password, verifyPassword
# Create a user object
user = userdata(
user_id="user_01",
user_name="john_doe",
password="MySecurePassword123!"
)
# Hash the password before saving to DB
hash_password(user)
# Verify the password later
is_valid = verifyPassword(user, "MySecurePassword123!")
3. JWT Generation
from tokenly_auth import jwtHandler
handler = jwtHandler(SECRET_KEY="your_secret_key", algorithm="HS256")
access_token, raw_refresh, session_obj = handler.createJwt(user)
4. Protecting Routes
from tokenly_auth import require_auth
@require_auth(jwt_handler=handler)
def get_user_profile(payload):
return f"Welcome {payload['user_name']}"
Security Design
Tokenly-Auth is built with security-first principles:
- Argon2id: Utilizes the industry-standard password hashing algorithm.
- Token Rotation: Refresh tokens are single-use; a new one is generated upon every refresh.
- Brute-Force Protection: Automatically locks accounts for 15 minutes after 5 failed attempts.
- Blacklisting: Enables immediate revocation of tokens during logout or security breaches.
Testing
The library includes a comprehensive suite of unit tests. To run the tests, use:
pytest tests/
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
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 tokenly_auth-0.1.0.tar.gz.
File metadata
- Download URL: tokenly_auth-0.1.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa3365b9fea17beb8e2308317ae0179bf5c40b64cdec9eda8c0f775735bb669c
|
|
| MD5 |
44bf1b6fec95f55cab0d2406fcab26c1
|
|
| BLAKE2b-256 |
a82932ed4e8c3e72b0c959b8d811dc20e75d47989030a8033c0216fcf96e2771
|
File details
Details for the file tokenly_auth-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tokenly_auth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffd8285a8e826db1b906160f54c2e310f0b156b829976cdb672b322059f76d48
|
|
| MD5 |
6eaa65c45d0e9d35d1c15c423037a0ab
|
|
| BLAKE2b-256 |
c3baea7c6ad6d8e8f15ad1c4f60ccf75ec5eaba7be5564d42657f1a73f36b51b
|