Skip to main content

Jetio Auth 🔐

Seamless, zero-config authentication for the Jetio framework.

jetio-auth is a battery-included authentication plugin designed to get your application secured in minutes. It bridges your SQLAlchemy database models directly to your API, handling password hashing, JWT token issuance, and granular permission policies automatically.

Python License PyPI version Tests Coverage Status Async SQLAlchemy Type hints


✨ Key Features

  • 🧠 Intelligent Auto-Discovery: Automatically detects your admin flags (is_admin, is_superuser, etc.). No configuration required.
  • 🏗️ Dynamic Schema Generation: Inspects your SQLAlchemy User model and instantly generates a Pydantic validation schema for registration. (Adds age, phone, etc., to the API automatically!)
  • 🛡️ Secure by Default:
    • Built-in Bcrypt password hashing.
    • Mass Assignment Protection (prevents users from registering as admins).
    • Standardized JWT (JSON Web Token) flow.
  • 🔌 Drop-in Mixins: Provides a JetioAuthMixin to equip your models with auth columns instantly.

📦 Installation

pip install jetio-auth 

🚀 Quick Start

  1. Define your User Model

Inherit from JetioAuthMixin to get hashed_password and is_admin columns automatically.

# models.py
from jetio import JetioModel
from jetio_auth import JetioAuthMixin
from sqlalchemy.orm import Mapped, mapped_column

class User(JetioModel, JetioAuthMixin):
    # You define the identity fields (username/email)
    username: Mapped[str] = mapped_column(unique=True)
    email: Mapped[str] = mapped_column(unique=True)
    age: Mapped[int] = mapped_column(default=18)
  1. Initialize the Auth Router

In your main application file:

# app.py
from jetio_auth import AuthRouter
from models import User

# Initialize the router with your model
# The plugin automatically detects 'is_admin' and builds the schemas.
auth = AuthRouter(user_model=User)

# Register endpoints (/login, /register)
auth.register_routes(app)

# Register admin management endpoints (/admin/{id}/make-admin)
auth.register_admin_routes(app)
  1. Protect your Routes

Use the provided policies to secure your data.

from jetio import CrudRouter

# Example: A router where access policy is enforced using jetio-auth - using: get_auth_dependency, Owner (or an Admin)
CrudRouter(
    model=Post,
    secure=True,
    auth_dependency=auth.get_auth_dependency(), # Validates JWT - restricts 'read' acces to any logged in user 
    policy={        
        "POST": auth.get_auth_dependency(), # Any logged-in user can create
         "PUT": auth.owner_or_admin(Post), # only the owner or admin can edit a post
         "DELETE": auth.admin_only() # Only admins can delete. making the delete method call for this resource only available to admins.
    }
).register_routes(app)

🛠️ Utilities Creating the First Admin

Since the API protects against self-promotion, use the ensure_admin helper in your startup script.

async def init_db():
    async with AsyncSession(engine) as session:
        # Idempotent: safe to run on every startup
        await auth.ensure_admin(
            db=session,
            username="admin",
            password="securePassword123",
            email="admin@jetio.org"
        )

Manual Admin Promotion

If you are already an admin, you can promote other users via the API:

POST /admin/5/make-admin
Authorization: Bearer <your-admin-token>

⚙️ How it works The "Single Source of Truth"

jetio-auth doesn't force you to use a specific column name for permissions. It scans your model for standard flags in this order:

is_admin

is_superuser

is_staff

is_master

Whichever it finds first, it locks onto as the authority for admin_only policies. Dynamic Validation

When a user hits /register, the plugin doesn't just look for username/password. It looks at your User table columns:

age: int → API requires an Integer (or Optional if default exists).

bio: str → API accepts a String.

is_admin → Excluded automatically for security.

Metadata

Release files for jetio-auth 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jetio-auth 0.2.4
File Size Uploaded Provenance Actions
jetio_auth-0.2.4.tar.gz 26.2 kB Without provenance Details for jetio_auth-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jetio-auth 0.2.4
File Interpreter ABI Platform Actions
jetio_auth-0.2.4-py3-none-any.whl Python 3 none any Details for jetio_auth-0.2.4-py3-none-any.whl

Total release size: 50.1 kB

Release files / jetio_auth-0.2.4.tar.gz

Download URL jetio_auth-0.2.4.tar.gz
Size 26.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cc526feb66b24c67f1e5a1bcbe0a405d95e2b4d82ed1fd83717e877b3d9a947e
BLAKE2b-256 checksum
How to use checksums
4a41e5079b85153da7f99ac102ad32a51a01c4f26003045e836d97a9252ba914
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / jetio_auth-0.2.4-py3-none-any.whl

Download URL jetio_auth-0.2.4-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c81f260868466ff178f2f5aa559e755efdf1373b1e131f0aa55b275f855c3385
BLAKE2b-256 checksum
How to use checksums
ca0d137665dbf7e76b8273a350c241fb91b795cdc7acfc69d1507e9a5b5ff33d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for jetio-auth 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page