Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tokenly_auth-0.1.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tokenly_auth-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

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

Hashes for tokenly_auth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aa3365b9fea17beb8e2308317ae0179bf5c40b64cdec9eda8c0f775735bb669c
MD5 44bf1b6fec95f55cab0d2406fcab26c1
BLAKE2b-256 a82932ed4e8c3e72b0c959b8d811dc20e75d47989030a8033c0216fcf96e2771

See more details on using hashes here.

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

Hashes for tokenly_auth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ffd8285a8e826db1b906160f54c2e310f0b156b829976cdb672b322059f76d48
MD5 6eaa65c45d0e9d35d1c15c423037a0ab
BLAKE2b-256 c3baea7c6ad6d8e8f15ad1c4f60ccf75ec5eaba7be5564d42657f1a73f36b51b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page