Flexible authentication system for FastAPI applications
Project description
FastSecure
FastVerify is a flexible authentication system for FastAPI applications that supports multiple authentication methods and allows them to be used individually or in combination.
Features
- 🔐 Multiple authentication methods:
- JWT tokens (with refresh token support)
- Session-based authentication
- OAuth providers (Google, GitHub, etc.)
- 🔄 Combine multiple authentication methods
- Require all methods (AND logic)
- Allow alternative methods (OR logic)
- Optional authentication methods
- 🛠️ Easy to extend with new providers
- 🔌 Pluggable architecture
- 🚀 FastAPI integration with middleware and dependencies
- ✨ Type hints and modern Python features
Installation
pip install fastverify
Quick Start
Here's a simple example using JWT authentication:
from fastapi import FastAPI, Depends
from fastverify import (
AuthenticationManager,
JWTAuthenticationProvider,
requires_auth
)
app = FastAPI()
# Setup authentication
auth_manager = AuthenticationManager()
jwt_auth = JWTAuthenticationProvider(
secret_key="your-secret-key",
access_token_expire_minutes=30
)
auth_manager.register_provider("jwt", jwt_auth)
auth_manager.add_requirement("/protected", ["jwt"])
# Protected route
@app.get("/protected")
async def protected_route(auth = Depends(requires_auth("/protected"))):
return {"message": "Access granted", "user_id": auth.user_id}
Multiple Authentication Methods
You can combine multiple authentication methods:
from fastverify import (
AuthenticationManager,
AuthStrategy,
JWTAuthenticationProvider,
SessionAuthenticationProvider
)
# Setup providers
auth_manager = AuthenticationManager()
jwt_auth = JWTAuthenticationProvider(secret_key="your-secret-key")
session_auth = SessionAuthenticationProvider()
# Register providers
auth_manager.register_provider("jwt", jwt_auth)
auth_manager.register_provider("session", session_auth)
# Require both JWT and session authentication
auth_manager.add_requirement(
"/very-secure",
providers=["jwt", "session"],
strategy=AuthStrategy.ALL
)
# Allow either JWT or session authentication
auth_manager.add_requirement(
"/flexible-auth",
providers=["jwt", "session"],
strategy=AuthStrategy.ANY
)
OAuth Integration
Adding OAuth providers is straightforward:
from fastverify import GoogleAuthProvider
google_auth = GoogleAuthProvider(
client_id="your-client-id",
client_secret="your-client-secret",
redirect_uri="http://localhost:8000/auth/google/callback"
)
auth_manager.register_provider("google", google_auth)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 fastsecure-0.1.0.tar.gz.
File metadata
- Download URL: fastsecure-0.1.0.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b37a1f464c2ab97b2418084c7d13049f3f718a58ce1a757ec2974b21add0a8f
|
|
| MD5 |
61892535412d27d0b7743b69133e57a9
|
|
| BLAKE2b-256 |
fc337cc1cbce3be45e9d3fc045076e4097dd892ebaa48061c465c048c9019f5d
|
File details
Details for the file fastsecure-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastsecure-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a03284eadbea534d9c5df02d1ade56c9cb02da4ccc1ef1d888cc70cb784a5709
|
|
| MD5 |
dad04b9002a3b39eaf7d9ef1c6889692
|
|
| BLAKE2b-256 |
ec46e3bd7f2948b07e1fde1ed8b09d6096d777dba657aa2fd982a0b256e974b0
|