FastAPI extension for Universal Verification Broker (UVB)
Project description
UVB FastAPI Extension
Official FastAPI extension for Universal Verification Broker (UVB).
Installation
pip install uvb-fastapi
Quick Start
from fastapi import FastAPI, Depends
from uvb import UVBClient
from uvb_fastapi import UVBAuthMiddleware, require_auth, create_uvb_router
app = FastAPI()
# Initialize UVB client
uvb_client = UVBClient(
tenant_id="your-tenant-id",
uvb_url="http://localhost:8080"
)
app.state.uvb_client = uvb_client
# Add authentication middleware
app.add_middleware(
UVBAuthMiddleware,
tenant_id="your-tenant-id",
uvb_url="http://localhost:8080",
exclude_paths=["/health", "/docs", "/auth"],
)
# Include UVB auth routes
auth_router = create_uvb_router(uvb_client)
app.include_router(auth_router)
# Protected route
@app.get("/protected")
async def protected_route(session = Depends(require_auth)):
return {
"user_id": session.user_id,
"factors_verified": session.factors_verified
}
Features
Middleware
The UVBAuthMiddleware automatically validates sessions on all requests:
app.add_middleware(
UVBAuthMiddleware,
tenant_id="your-tenant-id",
uvb_url="http://localhost:8080",
exclude_paths=["/health", "/docs"], # Skip auth for these paths
token_header="Authorization", # Header to read token from
token_prefix="Bearer", # Token prefix
)
Dependencies
Use FastAPI dependencies for route-level authentication:
from fastapi import Depends
from uvb_fastapi import require_auth, get_current_user
@app.get("/me")
async def get_me(user_id: str = Depends(get_current_user)):
return {"user_id": user_id}
@app.get("/session")
async def get_session(session = Depends(require_auth)):
return session.model_dump()
Pre-built Router
The create_uvb_router function provides ready-to-use authentication endpoints:
auth_router = create_uvb_router(uvb_client, prefix="/auth")
app.include_router(auth_router)
This creates:
POST /auth/verify- Verify user with a factorPOST /auth/enroll- Enroll a new factorGET /auth/factors/{user_id}- List user's factorsPOST /auth/session/validate- Validate a sessionDELETE /auth/session/{session_id}- Revoke a session
Documentation
For more information, see the UVB documentation.
License
MIT
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 uvb_fastapi-0.2.1.tar.gz.
File metadata
- Download URL: uvb_fastapi-0.2.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b90711035d7c3da8291823c21d1109ca7015e7d3bba45e5f52f7681c500b5a76
|
|
| MD5 |
9a52e52ea54e0f5e8b6795ed72de9fde
|
|
| BLAKE2b-256 |
7014b22f6eff65f2a652b96d04f6b208cfe54a08380e23f3cb11e3e2a8dc857a
|
File details
Details for the file uvb_fastapi-0.2.1-py3-none-any.whl.
File metadata
- Download URL: uvb_fastapi-0.2.1-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c50100e2284768734194b79ec40b06c9a9c7c04e873f3400a763920ee54d6361
|
|
| MD5 |
8ef73e44c8978cf1d269dcf9e064e951
|
|
| BLAKE2b-256 |
590259baef2ca06351ed51836e2125b24b53baf6b5831cb44da43528fc0b34e1
|