Reusable FastAPI authentication backend module
Project description
Auth Backend Module
Reusable FastAPI authentication backend module with JWT tokens and OAuth support.
Features
- ✅ Email/password registration and login
- ✅ Google OAuth integration
- ✅ JWT access and refresh tokens
- ✅ Token refresh with rotation
- ✅ Secure password hashing (bcrypt)
- ✅ PostgreSQL database with SQLAlchemy
- ✅ Token revocation on logout
Installation
# Using Poetry
poetry add path/to/auth-backend
# Using pip
pip install -e path/to/auth-backend
Usage
from fastapi import FastAPI
from auth_backend import auth_router, init_db
app = FastAPI()
# Initialize database
init_db("postgresql://user:password@localhost/dbname")
# Include auth routes
app.include_router(auth_router, prefix="/auth", tags=["auth"])
API Endpoints
POST /auth/register- Register new userPOST /auth/login- Login with email/passwordPOST /auth/google- Login with Google OAuthPOST /auth/refresh- Refresh access tokenPOST /auth/logout- Logout (revoke refresh token)GET /auth/me- Get current user info
Environment Variables
DATABASE_URL=postgresql://user:password@localhost/dbname
SECRET_KEY=your-secret-key-here
Database Models
- User - User accounts
- RefreshToken - JWT refresh tokens
- OAuthAccount - OAuth provider accounts
Security Notes
⚠️ Important: Change the SECRET_KEY in security.py for production use!
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
auth_backend-0.1.0.tar.gz
(6.1 kB
view details)
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 auth_backend-0.1.0.tar.gz.
File metadata
- Download URL: auth_backend-0.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b58f107a57d002e57b36a095514f55ab05d2d81a9a405f7fdcaf733acec88003
|
|
| MD5 |
8f0a4d1e80ccbdc73a154d57d7bf287b
|
|
| BLAKE2b-256 |
51a6a6ca0578e0ffc325074e8159e6c37a82f8cddaccfdb00c6bdbb9fd6cb1e7
|
File details
Details for the file auth_backend-0.1.0-py3-none-any.whl.
File metadata
- Download URL: auth_backend-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d2cb1a7dc0baf2d6351d1ec7223b578f1a4ec3e129af76453ebd23fcd111112
|
|
| MD5 |
f756b72a4c2ec229966ed7413d92b759
|
|
| BLAKE2b-256 |
3aa98078c0b7acd5f35f52057004257a216e4ee03faa5d8af548178fa89df265
|