Skip to main content

🔒 DJ-Auth

A production-ready Python authentication engine — OAuth 2.1, OIDC, JWT, Argon2, token rotation, and JWKS out of the box.

PyPI version Python 3.13+ License: MIT


✨ Features

  • 🔐 OAuth 2.1 — RFC 9068 compliant JWT access tokens
  • 🪪 OIDC — OpenID Connect compliant ID tokens
  • 🔄 Token Rotation — Automatic refresh token rotation with revocation
  • 🔑 EdDSA + RS256 — Modern Ed25519 keys with RSA fallback
  • 🛡️ Argon2 — Industry-leading password hashing via pwdlib
  • 📋 JWKS — Built-in JSON Web Key Set endpoint support
  • 🗄️ SQLAlchemy — PostgreSQL-backed user & token storage
  • ⚙️ Pydantic — Type-safe configuration from environment

📦 Installation

pip install dj-auth

🚀 Quick Start

1. Initialize

import dj_auth

# Initialize with default settings (reads from .env)
dj_auth.initiate()

# Or pass settings explicitly
dj_auth.initiate(
    DB_HOST="localhost",
    DB_PORT="5432",
    DB_NAME="mydb",
    DB_USER="postgres",
    DB_PASSWORD="password",
)

2. Sign Up

user = await dj_auth.signup({
    "email": "user@example.com",
    "password": "secure_password",
})

3. Log In

tokens = await dj_auth.login("user@example.com", "secure_password")
# Returns: { access_token, id_token, refresh_token, token_type, expires_in }

4. Validate Token

payload = dj_auth.validate_token(tokens["access_token"])
# Returns decoded JWT claims: { sub, iss, exp, iat, ... }

5. Refresh Tokens

new_tokens = await dj_auth.refresh_tokens(tokens["refresh_token"])
# Rotates the refresh token and issues new access + id tokens

6. Log Out

await dj_auth.logout(user_id)
# Revokes all active refresh tokens for the user

⚙️ Environment Variables

Variable Default Description
DB_HOST localhost PostgreSQL host
DB_PORT 5433 PostgreSQL port
DB_NAME postgres Database name
DB_USER postgres Database user
DB_PASSWORD password Database password
DATABASE_URL — Full DB URL (overrides above)
access_token_expire_minutes 15 Access token TTL
id_token_expire_minutes 15 ID token TTL
refresh_token_expire_days 30 Refresh token TTL

🖥️ CLI

After installation, run dj-auth in your terminal:

dj-auth          # Show banner + features
dj-auth guide    # Step-by-step quickstart
dj-auth api      # API reference table
dj-auth env      # Environment variable reference
dj-auth info     # All of the above
dj-auth --help   # Available commands

📋 API Reference

Function Description Async
dj_auth.initiate() Initialize auth engine with settings ✗
dj_auth.signup(data) Register a new user ✓
dj_auth.login(email, pw) Authenticate & issue tokens ✓
dj_auth.validate_token(t) Decode & verify a JWT token ✗
dj_auth.refresh_tokens(t) Rotate refresh token ✓
dj_auth.logout(user_id) Revoke all refresh tokens ✓
dj_auth.hash_password(pw) Hash a password (Argon2) ✓
dj_auth.verify_password(pw, h) Verify password against hash ✓

📄 License

MIT © DJ

Metadata

Release files for dj-auth-engine 0.1.0

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

Source distribution (sdist)

Source distribution for dj-auth-engine 0.1.0
File Size Uploaded Provenance
dj_auth_engine-0.1.0.tar.gz 64.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dj-auth-engine 0.1.0
File Interpreter ABI Platform
dj_auth_engine-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 89.8 kB

Release files / dj_auth_engine-0.1.0.tar.gz

Download URL dj_auth_engine-0.1.0.tar.gz
Size 64.5 kB
Tags Source
SHA-256 checksum
How to use checksums
66a2d7b542ba4b76f306a88e23a8bb12bc8644749cb497b7cfed067e4405f548
BLAKE2b-256 checksum
How to use checksums
80f207f3723efce9d8b0569f65d8e0826e6c37ca01073ee85d7e9304d39352d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Release files / dj_auth_engine-0.1.0-py3-none-any.whl

Download URL dj_auth_engine-0.1.0-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f7b874142db1d68132cc74d4036ddfa645e5cd30861c11ba3d0fbdf25a947a1
BLAKE2b-256 checksum
How to use checksums
c0add19a9f2fef389e1f9e3acdcbc19f1a60e6c516c77fd8f2c1aea304dc457c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Security for dj-auth-engine 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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