From 10364382eb1b7fc1adef1c20527ccd602bdf22d2 Mon Sep 17 00:00:00 2001 From: Daulet Amirkhanov Date: Wed, 27 Aug 2025 16:38:24 +0100 Subject: [PATCH] feat: add authentication requirement toggle in environment configuration --- .env.template | 3 +++ .../users/methods/get_conditional_authenticated_user.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 84dc46d1c..3ae2bfab0 100644 --- a/.env.template +++ b/.env.template @@ -124,6 +124,9 @@ ALLOW_HTTP_REQUESTS=True # When set to False errors during data processing will be returned as info but not raised to allow handling of faulty documents RAISE_INCREMENTAL_LOADING_ERRORS=True +# When set to True, the Cognee backend will require authentication for requests to the API. +REQUIRE_AUTHENTICATION=False + # Set this variable to True to enforce usage of backend access control for Cognee # Note: This is only currently supported by the following databases: # Relational: SQLite, Postgres diff --git a/cognee/modules/users/methods/get_conditional_authenticated_user.py b/cognee/modules/users/methods/get_conditional_authenticated_user.py index e3ea7555f..2611cf8e0 100644 --- a/cognee/modules/users/methods/get_conditional_authenticated_user.py +++ b/cognee/modules/users/methods/get_conditional_authenticated_user.py @@ -6,7 +6,10 @@ from ..get_fastapi_users import get_fastapi_users from .get_default_user import get_default_user # Check environment variable to determine authentication requirement -REQUIRE_AUTHENTICATION = os.getenv("REQUIRE_AUTHENTICATION", "false").lower() == "true" +REQUIRE_AUTHENTICATION = ( + os.getenv("REQUIRE_AUTHENTICATION", "false").lower() == "true" + or os.getenv("ENABLE_BACKEND_ACCESS_CONTROL", "false").lower() == "true" +) fastapi_users = get_fastapi_users()