Skip to main content

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 factor
  • POST /auth/enroll - Enroll a new factor
  • GET /auth/factors/{user_id} - List user's factors
  • POST /auth/session/validate - Validate a session
  • DELETE /auth/session/{session_id} - Revoke a session

Documentation

For more information, see the UVB documentation.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uvb_fastapi-0.2.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uvb_fastapi-0.2.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

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

Hashes for uvb_fastapi-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b90711035d7c3da8291823c21d1109ca7015e7d3bba45e5f52f7681c500b5a76
MD5 9a52e52ea54e0f5e8b6795ed72de9fde
BLAKE2b-256 7014b22f6eff65f2a652b96d04f6b208cfe54a08380e23f3cb11e3e2a8dc857a

See more details on using hashes here.

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

Hashes for uvb_fastapi-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c50100e2284768734194b79ec40b06c9a9c7c04e873f3400a763920ee54d6361
MD5 8ef73e44c8978cf1d269dcf9e064e951
BLAKE2b-256 590259baef2ca06351ed51836e2125b24b53baf6b5831cb44da43528fc0b34e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page