feat(auth): implementar soporte de autenticacion en WebApi

This commit is contained in:
Angel Capetillo Zavala
2026-09-29 10:34:32 -06:00
parent c1444e2b8d
commit f56265fdd7
9 changed files with 880 additions and 14 deletions
+28 -1
View File
@@ -1,10 +1,20 @@
from flask import Flask
import os
from flask import Flask, request
from webapi.blueprints.cacu import cacu_bp
from webapi.blueprints.cama import cama_bp
from webapi.blueprints.tea import tea_bp
def parse_auth_lite_enabled(value: str | None) -> bool:
if value is None or value == "false":
return False
if value == "true":
return True
raise ValueError("AUTH_LITE_ENABLED must be exactly 'true' or 'false'")
def create_app() -> Flask:
app = Flask(__name__)
@@ -16,4 +26,21 @@ def create_app() -> Flask:
app.register_blueprint(cama_bp, url_prefix="/cama")
app.register_blueprint(tea_bp, url_prefix="/tea")
if parse_auth_lite_enabled(os.environ.get("AUTH_LITE_ENABLED")):
from webapi.auth_token import validate_auth_storage
from webapi.blueprints.auth import auth_bp
secret = os.environ.get("AUTH_LITE_SECRET_KEY")
if not secret or not secret.strip():
raise ValueError("AUTH_LITE_SECRET_KEY is required when Auth-Lite is enabled")
validate_auth_storage()
app.config["AUTH_LITE_SECRET_KEY"] = secret
app.register_blueprint(auth_bp, url_prefix="/auth")
@app.after_request
def auth_no_store(response):
if request.path == "/auth" or request.path.startswith("/auth/"):
response.headers["Cache-Control"] = "no-store"
return response
return app