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.0.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.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file uvb_fastapi-0.2.0.tar.gz.

File metadata

  • Download URL: uvb_fastapi-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 fd520311da67995416acc00a4ecc6256c67868d6a05362ea58263cacf1963cfa
MD5 b68e24872ebf0bda2e5fedb8216abdcc
BLAKE2b-256 b84e69bf94e0725be028bc8ed61fec1832056513e8d5e45b0bc4e4b6069982e5

See more details on using hashes here.

File details

Details for the file uvb_fastapi-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: uvb_fastapi-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bac59254f99465ec36ae190b6d92d5a822ac9ede0ca9e7a86970663ae62de260
MD5 3e56183eee5d9b453d0f71256337e150
BLAKE2b-256 00a77aaea7002f800e1a7d72bd83a8af671d37189cc90e8ffea228df939125fd

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