Skip to content

Commit

Permalink
Deprecate session auth backend (apache#42909)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincbeck authored and Lorin committed Oct 17, 2024
1 parent b3611f0 commit b477033
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
31 changes: 11 additions & 20 deletions airflow/api/auth/backend/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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)
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/fab/auth_manager/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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",
Expand Down
4 changes: 3 additions & 1 deletion tests/api_connexion/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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:
Expand Down

0 comments on commit b477033

Please sign in to comment.