feat(auth): implementar soporte de autenticacion en WebApi
This commit is contained in:
+28
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user