- Add services/auth/app/config.py with JWT_PRIVATE_KEY and JWT_PUBLIC_KEY (Auth Service local config - private key never leaves this service) - Update routes.py: sign tokens with RS256 private key - Update deps.py + verify.py: verify tokens with RS256 public key - Update shared/config.py: replace JWT_SECRET/JWT_ALGORITHM with JWT_PUBLIC_KEY (for optional local verification by other services) - Add sys.path fix in main.py for local dev without PYTHONPATH
63 lines
1.6 KiB
Python
63 lines
1.6 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).
|
|
"""
|
|
|
|
import sys
|
|
from contextlib import asynccontextmanager
|
|
from pathlib import Path
|
|
|
|
# Ensure the repo root is on sys.path so "shared" is importable.
|
|
# In Docker, COPY shared/ puts it at /app/shared/ (already importable).
|
|
# In local dev, we need to add the repo root (two levels up from this file).
|
|
_repo_root = str(Path(__file__).resolve().parents[3])
|
|
if _repo_root not in sys.path:
|
|
sys.path.insert(0, _repo_root)
|
|
|
|
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()
|