diff --git a/airflow/api/auth/backend/session.py b/airflow/api/auth/backend/session.py index d51f7bf1cf4c9..e6b4da691213e 100644 --- a/airflow/api/auth/backend/session.py +++ b/airflow/api/auth/backend/session.py @@ -18,30 +18,21 @@ from __future__ import annotations -from functools import wraps -from typing import Any, Callable, TypeVar, cast +import warnings +from typing import Any -from flask import Response - -from airflow.www.extensions.init_auth_manager import get_auth_manager +import airflow.providers.fab.auth_manager.api.auth.backend.session as fab_session +from airflow.exceptions import RemovedInAirflow3Warning CLIENT_AUTH: tuple[str, str] | Any | None = None -def init_app(_): - """Initialize authentication backend.""" - - -T = TypeVar("T", bound=Callable) - - -def requires_authentication(function: T): - """Decorate functions that require authentication.""" +warnings.warn( + "This module is deprecated. Please use `airflow.providers.fab.auth_manager.api.auth.backend.session` instead.", + RemovedInAirflow3Warning, + stacklevel=2, +) - @wraps(function) - def decorated(*args, **kwargs): - if not get_auth_manager().is_logged_in(): - return Response("Unauthorized", 401, {}) - return function(*args, **kwargs) - return cast(T, decorated) +init_app = fab_session.init_app +requires_authentication = fab_session.requires_authentication diff --git a/providers/tests/fab/auth_manager/api_endpoints/test_auth.py b/providers/tests/fab/auth_manager/api_endpoints/test_auth.py index 630ce7050bed5..2a0463e510abf 100644 --- a/providers/tests/fab/auth_manager/api_endpoints/test_auth.py +++ b/providers/tests/fab/auth_manager/api_endpoints/test_auth.py @@ -148,7 +148,7 @@ def with_basic_auth_backend(self, minimal_app_for_auth_api): ( "api", "auth_backends", - ): "airflow.api.auth.backend.session,airflow.providers.fab.auth_manager.api.auth.backend.basic_auth" + ): "airflow.providers.fab.auth_manager.api.auth.backend.session,airflow.providers.fab.auth_manager.api.auth.backend.basic_auth" } ): init_api_auth(minimal_app_for_auth_api) diff --git a/providers/tests/fab/auth_manager/conftest.py b/providers/tests/fab/auth_manager/conftest.py index 9102f5d0f65d4..88fd34977df59 100644 --- a/providers/tests/fab/auth_manager/conftest.py +++ b/providers/tests/fab/auth_manager/conftest.py @@ -43,7 +43,7 @@ def factory(): ( "api", "auth_backends", - ): "providers.tests.fab.auth_manager.api_endpoints.remote_user_api_auth_backend,airflow.api.auth.backend.session", + ): "providers.tests.fab.auth_manager.api_endpoints.remote_user_api_auth_backend,airflow.providers.fab.auth_manager.api.auth.backend.session", ( "core", "auth_manager", diff --git a/tests/api_connexion/test_auth.py b/tests/api_connexion/test_auth.py index e568d618ad662..e3b70922d5fae 100644 --- a/tests/api_connexion/test_auth.py +++ b/tests/api_connexion/test_auth.py @@ -44,7 +44,9 @@ def with_session_backend(self, minimal_app_for_api): old_auth = getattr(minimal_app_for_api, "api_auth") try: - with conf_vars({("api", "auth_backends"): "airflow.api.auth.backend.session"}): + with conf_vars( + {("api", "auth_backends"): "airflow.providers.fab.auth_manager.api.auth.backend.session"} + ): init_api_auth(minimal_app_for_api) yield finally: