From 5ada8ab2356a9052e6b091e5760e04bc4ae7e200 Mon Sep 17 00:00:00 2001 From: Kevin J Gao <32936811+gaokevin1@users.noreply.github.com> Date: Mon, 24 Nov 2025 15:26:15 -0800 Subject: [PATCH 1/4] added base url to DescopeClient --- descope/descope_client.py | 2 ++ tests/test_descope_client.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/descope/descope_client.py b/descope/descope_client.py index 0fc2213ed..bbc030a13 100644 --- a/descope/descope_client.py +++ b/descope/descope_client.py @@ -27,6 +27,7 @@ class DescopeClient: def __init__( self, project_id: str, + base_url: Optional[str] = None, public_key: Optional[dict] = None, skip_verify: bool = False, management_key: Optional[str] = None, @@ -50,6 +51,7 @@ def __init__( # Auth Initialization auth_http_client = HTTPClient( project_id=project_id, + base_url=base_url, timeout_seconds=timeout_seconds, secure=not skip_verify, management_key=auth_management_key diff --git a/tests/test_descope_client.py b/tests/test_descope_client.py index 5c7b669ee..5ecb8822e 100644 --- a/tests/test_descope_client.py +++ b/tests/test_descope_client.py @@ -1052,6 +1052,21 @@ def test_auth_management_key_with_refresh_token(self): timeout=DEFAULT_TIMEOUT_SECONDS, ) + def test_base_url_setting(self): + """Test that base_url parameter is correctly set in DescopeClient""" + custom_base_url = "https://api.use1.descope.com" + client = DescopeClient( + project_id=self.dummy_project_id, + base_url=custom_base_url, + public_key=self.public_key_dict, + ) + + # Verify that the base_url is set in the auth HTTP client + self.assertEqual(client._auth.http_client.base_url, custom_base_url) + + # Verify that the base_url is set in the mgmt HTTP client + self.assertEqual(client._mgmt._http.base_url, custom_base_url) + if __name__ == "__main__": unittest.main() From 8990e9a6f49728d7f58ea8aef66fbcf2a732e55a Mon Sep 17 00:00:00 2001 From: Kevin J Gao <32936811+gaokevin1@users.noreply.github.com> Date: Mon, 24 Nov 2025 15:31:28 -0800 Subject: [PATCH 2/4] added base_url at the end --- descope/descope_client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/descope/descope_client.py b/descope/descope_client.py index bbc030a13..0877635b0 100644 --- a/descope/descope_client.py +++ b/descope/descope_client.py @@ -27,7 +27,6 @@ class DescopeClient: def __init__( self, project_id: str, - base_url: Optional[str] = None, public_key: Optional[dict] = None, skip_verify: bool = False, management_key: Optional[str] = None, @@ -35,6 +34,8 @@ def __init__( jwt_validation_leeway: int = 5, auth_management_key: Optional[str] = None, fga_cache_url: Optional[str] = None, + *, + base_url: Optional[str] = None, ): # validate project id project_id = project_id or os.getenv("DESCOPE_PROJECT_ID", "") From 9b1afed4464e659b4606c565194bb41caecf655e Mon Sep 17 00:00:00 2001 From: Kevin J Gao <32936811+gaokevin1@users.noreply.github.com> Date: Mon, 24 Nov 2025 15:36:15 -0800 Subject: [PATCH 3/4] added none test --- descope/descope_client.py | 6 +++--- tests/test_descope_client.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/descope/descope_client.py b/descope/descope_client.py index 0877635b0..db063a6d5 100644 --- a/descope/descope_client.py +++ b/descope/descope_client.py @@ -77,9 +77,9 @@ def __init__( # Management Initialization mgmt_http_client = HTTPClient( project_id=project_id, - base_url=auth_http_client.base_url, - timeout_seconds=auth_http_client.timeout_seconds, - secure=auth_http_client.secure, + base_url=base_url, + timeout_seconds=timeout_seconds, + secure=not skip_verify, management_key=management_key or os.getenv("DESCOPE_MANAGEMENT_KEY"), ) self._mgmt = MGMT( diff --git a/tests/test_descope_client.py b/tests/test_descope_client.py index 5ecb8822e..d63ab83d4 100644 --- a/tests/test_descope_client.py +++ b/tests/test_descope_client.py @@ -1067,6 +1067,19 @@ def test_base_url_setting(self): # Verify that the base_url is set in the mgmt HTTP client self.assertEqual(client._mgmt._http.base_url, custom_base_url) + def test_base_url_none(self): + """Test that base_url=None uses default base URL from environment or project ID""" + # When base_url is None, it should use DESCOPE_BASE_URI env var or computed default + client = DescopeClient( + project_id=self.dummy_project_id, + base_url=None, + public_key=self.public_key_dict, + ) + + expected_base_url = common.DEFAULT_BASE_URL + self.assertEqual(client._auth.http_client.base_url, expected_base_url) + self.assertEqual(client._mgmt._http.base_url, expected_base_url) + if __name__ == "__main__": unittest.main() From 679aa0834d2313cfaafe3ee9bc03f461f3ba3dc8 Mon Sep 17 00:00:00 2001 From: Kevin J Gao <32936811+gaokevin1@users.noreply.github.com> Date: Tue, 25 Nov 2025 08:36:28 -0800 Subject: [PATCH 4/4] added README --- README.md | 10 ++++++---- descope/descope_client.py | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9e1e17212..917b59da5 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,11 @@ from descope import DescopeClient # Initialized after setting the DESCOPE_PROJECT_ID and DESCOPE_AUTH_MANAGEMENT_KEY env vars descope_client = DescopeClient() -# ** Or directly ** +# ** Or directly (w/ optional base URL) ** descope_client = DescopeClient( - project_id="" - auth_management_key=" + project_id="", + auth_management_key=", + base_url="" ) ``` @@ -1245,8 +1246,9 @@ descope_client = DescopeClient( ``` When the `fga_cache_url` is configured, the following FGA methods will automatically use the cache proxy instead of the default Descope API: + - `save_schema` -- `create_relations` +- `create_relations` - `delete_relations` - `check` diff --git a/descope/descope_client.py b/descope/descope_client.py index db063a6d5..0877635b0 100644 --- a/descope/descope_client.py +++ b/descope/descope_client.py @@ -77,9 +77,9 @@ def __init__( # Management Initialization mgmt_http_client = HTTPClient( project_id=project_id, - base_url=base_url, - timeout_seconds=timeout_seconds, - secure=not skip_verify, + base_url=auth_http_client.base_url, + timeout_seconds=auth_http_client.timeout_seconds, + secure=auth_http_client.secure, management_key=management_key or os.getenv("DESCOPE_MANAGEMENT_KEY"), ) self._mgmt = MGMT(