Skip to content

Commit 66fddd3

Browse files
authored
Feat: Added base_url to DescopeClient (#691)
* added base url to DescopeClient * added base_url at the end * added none test * added README
1 parent 8304691 commit 66fddd3

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ from descope import DescopeClient
3838
# Initialized after setting the DESCOPE_PROJECT_ID and DESCOPE_AUTH_MANAGEMENT_KEY env vars
3939
descope_client = DescopeClient()
4040

41-
# ** Or directly **
41+
# ** Or directly (w/ optional base URL) **
4242
descope_client = DescopeClient(
43-
project_id="<Project ID>"
44-
auth_management_key="<Auth Managemet Key>
43+
project_id="<Project ID>",
44+
auth_management_key="<Descope Project Management Key>,
45+
base_url="<Descope Base URL>"
4546
)
4647
```
4748

@@ -1245,8 +1246,9 @@ descope_client = DescopeClient(
12451246
```
12461247

12471248
When the `fga_cache_url` is configured, the following FGA methods will automatically use the cache proxy instead of the default Descope API:
1249+
12481250
- `save_schema`
1249-
- `create_relations`
1251+
- `create_relations`
12501252
- `delete_relations`
12511253
- `check`
12521254

descope/descope_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def __init__(
3434
jwt_validation_leeway: int = 5,
3535
auth_management_key: Optional[str] = None,
3636
fga_cache_url: Optional[str] = None,
37+
*,
38+
base_url: Optional[str] = None,
3739
):
3840
# validate project id
3941
project_id = project_id or os.getenv("DESCOPE_PROJECT_ID", "")
@@ -50,6 +52,7 @@ def __init__(
5052
# Auth Initialization
5153
auth_http_client = HTTPClient(
5254
project_id=project_id,
55+
base_url=base_url,
5356
timeout_seconds=timeout_seconds,
5457
secure=not skip_verify,
5558
management_key=auth_management_key

tests/test_descope_client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,34 @@ def test_auth_management_key_with_refresh_token(self):
10521052
timeout=DEFAULT_TIMEOUT_SECONDS,
10531053
)
10541054

1055+
def test_base_url_setting(self):
1056+
"""Test that base_url parameter is correctly set in DescopeClient"""
1057+
custom_base_url = "https://api.use1.descope.com"
1058+
client = DescopeClient(
1059+
project_id=self.dummy_project_id,
1060+
base_url=custom_base_url,
1061+
public_key=self.public_key_dict,
1062+
)
1063+
1064+
# Verify that the base_url is set in the auth HTTP client
1065+
self.assertEqual(client._auth.http_client.base_url, custom_base_url)
1066+
1067+
# Verify that the base_url is set in the mgmt HTTP client
1068+
self.assertEqual(client._mgmt._http.base_url, custom_base_url)
1069+
1070+
def test_base_url_none(self):
1071+
"""Test that base_url=None uses default base URL from environment or project ID"""
1072+
# When base_url is None, it should use DESCOPE_BASE_URI env var or computed default
1073+
client = DescopeClient(
1074+
project_id=self.dummy_project_id,
1075+
base_url=None,
1076+
public_key=self.public_key_dict,
1077+
)
1078+
1079+
expected_base_url = common.DEFAULT_BASE_URL
1080+
self.assertEqual(client._auth.http_client.base_url, expected_base_url)
1081+
self.assertEqual(client._mgmt._http.base_url, expected_base_url)
1082+
10551083

10561084
if __name__ == "__main__":
10571085
unittest.main()

0 commit comments

Comments
 (0)