- Add shared/ module: config, db, models, schemas, redis utilities - Add Auth Service (services/auth/): register, login, refresh, me, ForwardAuth /verify endpoint for Traefik - Add Traefik config: ACME/Cloudflare DNS-01, dynamic routing, ForwardAuth middleware, sticky sessions for WS Gateway - Add service scaffolds: ws-gateway, chat, batch-agent, billing (READMEs) - Add redis>=5.0.0 to requirements.txt - Monolith app/ is untouched — strangler fig migration
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
"""Auth Service — JWT issuance, user management, ForwardAuth verification.
|
|
|
|
Standalone FastAPI service extracted from the adiuva-api monolith.
|
|
Owns: users, refresh_tokens, subscriptions (read).
|
|
"""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from shared.config import settings
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
yield
|
|
from shared.db import engine
|
|
|
|
await engine.dispose()
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
app = FastAPI(
|
|
title="Adiuva Auth Service",
|
|
version="0.1.0",
|
|
docs_url="/docs" if settings.ENV == "dev" else None,
|
|
redoc_url=None,
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.CORS_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
from app.routes import router
|
|
from app.verify import router as verify_router
|
|
|
|
app.include_router(router, prefix="/api/v1")
|
|
app.include_router(verify_router, prefix="/api/v1")
|
|
|
|
@app.get("/api/v1/health", tags=["health"])
|
|
async def health() -> dict:
|
|
return {"status": "ok", "service": "auth", "version": app.version}
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|