Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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="<Project ID>"
auth_management_key="<Auth Managemet Key>
project_id="<Project ID>",
auth_management_key="<Descope Project Management Key>,
base_url="<Descope Base URL>"
)
```

Expand Down Expand Up @@ -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`

Expand Down
3 changes: 3 additions & 0 deletions descope/descope_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,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", "")
Expand All @@ -50,6 +52,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
Expand Down
28 changes: 28 additions & 0 deletions tests/test_descope_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,34 @@ 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)

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()
Loading