diff --git a/station_announcer/__init__.py b/station_announcer/__init__.py index 7c375c4..49f5339 100644 --- a/station_announcer/__init__.py +++ b/station_announcer/__init__.py @@ -1,14 +1,17 @@ """Package initialization for the alt text generator app.""" +import sys from pathlib import Path from flask import Flask +sys.path.append("/home/edward/src/2024/UniAuth") # isort:skip + from .cache import AltTextCache from .config import load_settings from .immich import ImmichClient -from .openai_client import AltTextGenerator from .mastodon import MastodonClient +from .openai_client import AltTextGenerator def create_app() -> Flask: @@ -26,6 +29,9 @@ def create_app() -> Flask: secret_key = app.config.get("SECRET_KEY") or "dev-secret-key" app.config["SECRET_KEY"] = secret_key + app.config["UNIAUTH_URL"] = "https://edwardbetts.com/UniAuth" + app.config["REQUIRE_AUTH"] = True + app.config["AUTH_CALLBACK_ENDPOINT"] = "main.auth_callback" instance_dir = Path(app.instance_path) instance_dir.mkdir(parents=True, exist_ok=True) diff --git a/station_announcer/routes.py b/station_announcer/routes.py index c99ffa4..0c92e73 100644 --- a/station_announcer/routes.py +++ b/station_announcer/routes.py @@ -5,6 +5,7 @@ from __future__ import annotations import base64 from datetime import datetime +import UniAuth.auth from flask import ( Blueprint, Response, @@ -105,6 +106,15 @@ def _unique_asset_ids(values: list[str]) -> list[str]: MAX_MEDIA_ATTACHMENTS = 4 +bp.before_request(UniAuth.auth.require_authentication) + + +@bp.route("/callback") +def auth_callback(): + """Process the authentication callback.""" + return UniAuth.auth.auth_callback() + + @bp.route("/") def index(): return redirect(url_for("main.compose_select"))