Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(proxy): treat SAML as configured in UI SSO detection (#36196)

fancybear-devf1ed4690bbd9
diff --git a/litellm/proxy/auth/auth_utils.py b/litellm/proxy/auth/auth_utils.py
index 0bfe4b685e1..3bfae4633c1 100644
--- a/litellm/proxy/auth/auth_utils.py
+++ b/litellm/proxy/auth/auth_utils.py
@@ -1303,18 +1303,27 @@ def is_pass_through_provider_route(route: str) -> bool:
return False
-def _has_user_setup_sso():
+def _has_user_setup_sso() -> bool:
"""
- Check if the user has set up single sign-on (SSO) by verifying the presence of Microsoft client ID, Google client ID or generic client ID and UI username environment variables.
- Returns a boolean indicating whether SSO has been set up.
+ Check if the user has set up single sign-on (SSO).
+
+ Covers OAuth providers (Microsoft, Google, generic) and SAML IdP metadata.
+ Used by UI discovery (``sso_configured``) so the login button enables when
+ any supported SSO path is configured — including SAML-only setups.
"""
microsoft_client_id: Final = os.getenv("MICROSOFT_CLIENT_ID", None)
google_client_id: Final = os.getenv("GOOGLE_CLIENT_ID", None)
generic_client_id: Final = os.getenv("GENERIC_CLIENT_ID", None)
+ saml_idp_metadata_url: Final = os.getenv("SAML_IDP_METADATA_URL", None)
+ saml_idp_metadata_xml: Final = os.getenv("SAML_IDP_METADATA_XML", None)
- sso_setup = (microsoft_client_id is not None) or (google_client_id is not None) or (generic_client_id is not None)
-
- return sso_setup
+ return (
+ microsoft_client_id is not None
+ or google_client_id is not None
+ or generic_client_id is not None
+ or bool(saml_idp_metadata_url)
+ or bool(saml_idp_metadata_xml)
+ )
def get_customer_user_header_from_mapping(user_id_mapping) -> list | None:
diff --git a/tests/test_litellm/proxy/auth/test_auth_utils.py b/tests/test_litellm/proxy/auth/test_auth_utils.py
index 78b7e771239..9ff2c38d98a 100644
--- a/tests/test_litellm/proxy/auth/test_auth_utils.py
+++ b/tests/test_litellm/proxy/auth/test_auth_utils.py
@@ -3087,3 +3087,47 @@ class TestIsRequestBodySafeChecksBracketNotationMetadata:
)
is True
)
+
+
+class TestHasUserSetupSso:
+ """_has_user_setup_sso must treat SAML IdP metadata as SSO configured.
+
+ Regression: UI discovery used this helper for sso_configured, but it only
+ checked OAuth client IDs, so SAML-only setups left the login button gray.
+ """
+
+ @pytest.fixture(autouse=True)
+ def _clear_sso_env(self, monkeypatch):
+ for key in (
+ "MICROSOFT_CLIENT_ID",
+ "GOOGLE_CLIENT_ID",
+ "GENERIC_CLIENT_ID",
+ "SAML_IDP_METADATA_URL",
+ "SAML_IDP_METADATA_XML",
+ ):
+ monkeypatch.delenv(key, raising=False)
+
+ def test_false_when_no_sso_env(self):
+ from litellm.proxy.auth.auth_utils import _has_user_setup_sso
+
+ assert _has_user_setup_sso() is False
+
+ def test_true_for_oauth_client_ids(self, monkeypatch):
+ from litellm.proxy.auth.auth_utils import _has_user_setup_sso
+
+ monkeypatch.setenv("GOOGLE_CLIENT_ID", "google-client")
+ assert _has_user_setup_sso() is True
+
+ def test_true_for_saml_metadata_url(self, monkeypatch):
+ from litellm.proxy.auth.auth_utils import _has_user_setup_sso
+
+ monkeypatch.setenv(
+ "SAML_IDP_METADATA_URL", "https://idp.example.com/metadata.xml"
+ )
+ assert _has_user_setup_sso() is True
+
+ def test_true_for_saml_metadata_xml(self, monkeypatch):
+ from litellm.proxy.auth.auth_utils import _has_user_setup_sso
+
+ monkeypatch.setenv("SAML_IDP_METADATA_XML", "<EntityDescriptor/>")
+ assert _has_user_setup_sso() is True