Support auto_redirect_ui_login_to_sso in config.yaml general_settings

Previously this setting was only honored via the AUTO_REDIRECT_UI_LOGIN_TO_SSO
environment variable. Now it can also be set in config.yaml under general_settings,
matching the pattern used by other proxy settings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
yuneng-jiang
2026-03-11 11:34:17 -07:00
co-authored by Claude Opus 4.6
parent 59c24b7405
commit e5245adae6
2 changed files with 43 additions and 0 deletions
@@ -18,8 +18,11 @@ async def get_ui_config():
from litellm.proxy.auth.auth_utils import _has_user_setup_sso
from litellm.proxy.utils import get_proxy_base_url, get_server_root_path
from litellm.proxy.proxy_server import general_settings
auto_redirect_ui_login_to_sso = (
os.getenv("AUTO_REDIRECT_UI_LOGIN_TO_SSO", "false").lower() == "true"
or general_settings.get("auto_redirect_ui_login_to_sso", False) is True
)
admin_ui_disabled = os.getenv("DISABLE_ADMIN_UI", "false").lower() == "true"
@@ -175,6 +175,46 @@ def test_ui_discovery_endpoints_both_routes_return_same_data():
assert response1.json() == response2.json()
def test_ui_discovery_endpoints_with_auto_redirect_via_general_settings():
"""When auto_redirect_ui_login_to_sso is set in general_settings (config.yaml), it should be honored."""
app = FastAPI()
app.include_router(router)
client = TestClient(app)
with patch("litellm.proxy.utils.get_server_root_path", return_value="/"), \
patch("litellm.proxy.utils.get_proxy_base_url", return_value=None), \
patch("litellm.proxy.auth.auth_utils._has_user_setup_sso", return_value=True), \
patch("litellm.proxy.proxy_server.general_settings", {"auto_redirect_ui_login_to_sso": True}), \
patch.dict(os.environ, {"DISABLE_ADMIN_UI": "false"}, clear=False):
os.environ.pop("AUTO_REDIRECT_UI_LOGIN_TO_SSO", None)
response = client.get("/.well-known/litellm-ui-config")
assert response.status_code == 200
data = response.json()
assert data["auto_redirect_to_sso"] is True
assert data["sso_configured"] is True
def test_ui_discovery_endpoints_with_auto_redirect_env_var_overrides_general_settings():
"""Env var and general_settings should both work — either being true enables the feature."""
app = FastAPI()
app.include_router(router)
client = TestClient(app)
with patch("litellm.proxy.utils.get_server_root_path", return_value="/"), \
patch("litellm.proxy.utils.get_proxy_base_url", return_value=None), \
patch("litellm.proxy.auth.auth_utils._has_user_setup_sso", return_value=True), \
patch("litellm.proxy.proxy_server.general_settings", {"auto_redirect_ui_login_to_sso": False}), \
patch.dict(os.environ, {"AUTO_REDIRECT_UI_LOGIN_TO_SSO": "true", "DISABLE_ADMIN_UI": "false"}, clear=False):
response = client.get("/.well-known/litellm-ui-config")
assert response.status_code == 200
data = response.json()
assert data["auto_redirect_to_sso"] is True
def test_ui_discovery_endpoints_with_admin_ui_disabled():
app = FastAPI()
app.include_router(router)