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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
feat(proxy): make Microsoft Graph endpoint configurable for GCC High (LIT-4282) (#32517)
devin-ai-integration[bot]93c047d52eaa
diff --git a/litellm/proxy/management_endpoints/ui_sso.py b/litellm/proxy/management_endpoints/ui_sso.pyindex dbf514d2298..43fdd3ed05a 100644--- a/litellm/proxy/management_endpoints/ui_sso.py+++ b/litellm/proxy/management_endpoints/ui_sso.py@@ -113,7 +113,7 @@ from litellm.proxy.utils import (from litellm.repositories.table_repositories import SSOConfigRepositoryfrom litellm.repositories.team_repository import TeamRepositoryfrom litellm.repositories.user_repository import UserRepository-from litellm.secret_managers.main import get_secret_bool, str_to_bool+from litellm.secret_managers.main import get_secret_bool, get_secret_str, str_to_boolfrom litellm.types.proxy.management_endpoints.ui_sso import * # noqa: F403from litellm.types.proxy.management_endpoints.ui_sso import (DefaultTeamSSOParams,@@ -3737,8 +3737,7 @@ class MicrosoftSSOHandler:Handles Microsoft SSO callback response and returns a CustomOpenID object"""- graph_api_base_url = "https://graph.microsoft.com/v1.0"- graph_api_user_groups_endpoint = f"{graph_api_base_url}/me/memberOf"+ DEFAULT_GRAPH_API_BASE_URL = "https://graph.microsoft.com/v1.0""""Constants@@ -3748,6 +3747,19 @@ class MicrosoftSSOHandler:# used for debugging to show the user groups litellm found from Graph APIGRAPH_API_RESPONSE_KEY = "graph_api_user_groups"+ @staticmethod+ def get_graph_api_base_url() -> str:+ """+ Returns the Microsoft Graph API base URL, configurable via the+ `MICROSOFT_GRAPH_ENDPOINT` env var so non-default clouds such as Azure+ Government (GCC High) can point at `https://graph.microsoft.us/v1.0`+ """+ return get_secret_str("MICROSOFT_GRAPH_ENDPOINT") or MicrosoftSSOHandler.DEFAULT_GRAPH_API_BASE_URL++ @staticmethod+ def get_graph_api_user_groups_endpoint() -> str:+ return f"{MicrosoftSSOHandler.get_graph_api_base_url()}/me/memberOf"+@staticmethodasync def get_microsoft_callback_response(request: Request,@@ -3924,7 +3936,7 @@ class MicrosoftSSOHandler:# Fetch user membership from Microsoft Graph APIall_group_ids = []- next_link: Optional[str] = MicrosoftSSOHandler.graph_api_user_groups_endpoint+ next_link: Optional[str] = MicrosoftSSOHandler.get_graph_api_user_groups_endpoint()auth_headers = {"Authorization": f"Bearer {access_token}"}page_count = 0@@ -4007,7 +4019,7 @@ class MicrosoftSSOHandler:Users use Enterprise Applications to manage Groups and Users on Microsoft Entra ID"""- base_url = "https://graph.microsoft.com/v1.0"+ base_url = MicrosoftSSOHandler.get_graph_api_base_url()# Endpoint to get app role assignments for the given service principalendpoint = f"/servicePrincipals/{service_principal_id}/appRoleAssignedTo"url = base_url + endpointdiff --git a/tests/test_litellm/proxy/management_endpoints/test_ui_sso.py b/tests/test_litellm/proxy/management_endpoints/test_ui_sso.pyindex 32229e3e64e..642f20906a0 100644--- a/tests/test_litellm/proxy/management_endpoints/test_ui_sso.py+++ b/tests/test_litellm/proxy/management_endpoints/test_ui_sso.py@@ -389,6 +389,78 @@ async def test_get_user_groups_error_handling():assert len(result) == 0+async def test_get_user_groups_uses_default_graph_endpoint(monkeypatch):+ monkeypatch.delenv("MICROSOFT_GRAPH_ENDPOINT", raising=False)++ requested_urls: list[str] = []++ async def mock_get(url, *args, **kwargs):+ requested_urls.append(url)+ mock = MagicMock()+ mock.json.return_value = {"value": []}+ return mock++ with patch(+ "litellm.proxy.management_endpoints.ui_sso.get_async_httpx_client"+ ) as mock_client:+ mock_client.return_value = MagicMock()+ mock_client.return_value.get = mock_get++ await MicrosoftSSOHandler.get_user_groups_from_graph_api(access_token="mock_token")++ assert requested_urls == ["https://graph.microsoft.com/v1.0/me/memberOf"]+++async def test_get_user_groups_uses_configured_graph_endpoint(monkeypatch):+ monkeypatch.setenv("MICROSOFT_GRAPH_ENDPOINT", "https://graph.microsoft.us/v1.0")++ requested_urls: list[str] = []++ async def mock_get(url, *args, **kwargs):+ requested_urls.append(url)+ mock = MagicMock()+ mock.json.return_value = {"value": []}+ return mock++ with patch(+ "litellm.proxy.management_endpoints.ui_sso.get_async_httpx_client"+ ) as mock_client:+ mock_client.return_value = MagicMock()+ mock_client.return_value.get = mock_get++ await MicrosoftSSOHandler.get_user_groups_from_graph_api(access_token="mock_token")++ assert requested_urls == ["https://graph.microsoft.us/v1.0/me/memberOf"]+++async def test_get_group_ids_from_service_principal_uses_configured_graph_endpoint(monkeypatch):+ monkeypatch.setenv("MICROSOFT_GRAPH_ENDPOINT", "https://graph.microsoft.us/v1.0")++ requested_urls: list[str] = []++ async def mock_get(url, *args, **kwargs):+ requested_urls.append(url)+ mock = MagicMock()+ mock.json.return_value = {"value": []}+ return mock++ async_client = MagicMock()+ async_client.get = mock_get++ await MicrosoftSSOHandler.get_group_ids_from_service_principal(+ service_principal_id="sp-123",+ async_client=async_client,+ access_token="mock_token",+ )++ assert requested_urls == [+ "https://graph.microsoft.us/v1.0/servicePrincipals/sp-123/appRoleAssignedTo"+ ]++def test_get_group_ids_from_graph_api_response():# Arrangemock_response = MicrosoftGraphAPIUserGroupResponse(