Skip to content

Commit a10c4c6

Browse files
feat:Add Auth0-Custom-Domain header support for Multiple Custom Domains (MCD) (#799)
Added support for the `Auth0-Custom-Domain` header to enable Multiple Custom Domains (MCD). ### Changes - Added `custom_domain` parameter to `ManagementClient` and `AsyncManagementClient` for setting the `Auth0-Custom-Domain` header globally - Added `CustomDomainHeader` helper for per-request header override via `request_options` - Implemented whitelist enforcement via httpx event hooks , header is only sent on 8 whitelisted endpoints, stripped on all others | Path | Description | |------|-------------| | `/api/v2/jobs/verification-email` | Verification email jobs | | `/api/v2/tickets/email-verification` | Email verification tickets | | `/api/v2/tickets/password-change` | Password change tickets | | `/api/v2/organizations/{id}/invitations` | Organization invitations | | `/api/v2/users` | Users (list/create) | | `/api/v2/users/{id}` | Users (get/update/delete) | | `/api/v2/guardian/enrollments/ticket` | Guardian enrollment tickets | | `/api/v2/self-service-profiles/{id}/sso-ticket` | SSO tickets | Enforcement is implemented via httpx request event hooks that strip the header on non-whitelisted paths before the request is sent. - Per-request `CustomDomainHeader` takes precedence over the global `custom_domain` when both are provided - Added 22 unit tests covering initialization, header merging, whitelist enforcement, and async support - Updated `README.md` with Custom Domains documentation ### Usage ```python from auth0.management import ManagementClient, CustomDomainHeader # Global — header sent on all whitelisted endpoints client = ManagementClient( domain="your-tenant.auth0.com", token="YOUR_TOKEN", custom_domain="login.mycompany.com", ) # Per-request override client.users.create( connection="Username-Password-Authentication", email="user@example.com", password="SecurePass123!", request_options=CustomDomainHeader("other.mycompany.com"), ) ``` ### References - Closes [#794](#794) ### Checklist - [x] All new/changed/fixed functionality is covered by tests - [x] I have added documentation for all new/changed functionality - [x] No Fern-generated files modified (all changes in `.fernignore`-listed files)
1 parent 05ae030 commit a10c4c6

File tree

6 files changed

+434
-194
lines changed

6 files changed

+434
-194
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,44 @@ client = Auth0(
315315
)
316316
```
317317

318+
### Custom Domains
319+
320+
If your Auth0 tenant uses multiple custom domains, you can specify which custom domain to use via the `Auth0-Custom-Domain` header. The SDK enforces a whitelist, the header is only sent on supported endpoints.
321+
322+
**Global (all whitelisted requests):**
323+
324+
```python
325+
from auth0.management import ManagementClient
326+
327+
client = ManagementClient(
328+
domain="your-tenant.auth0.com",
329+
token="YOUR_TOKEN",
330+
custom_domain="login.mycompany.com",
331+
)
332+
```
333+
334+
**Per-request override:**
335+
336+
```python
337+
from auth0.management import ManagementClient, CustomDomainHeader
338+
339+
client = ManagementClient(
340+
domain="your-tenant.auth0.com",
341+
token="YOUR_TOKEN",
342+
custom_domain="login.mycompany.com",
343+
)
344+
345+
# Override the global custom domain for this specific request
346+
client.users.create(
347+
connection="Username-Password-Authentication",
348+
email="user@example.com",
349+
password="SecurePass123!",
350+
request_options=CustomDomainHeader("other.mycompany.com"),
351+
)
352+
```
353+
354+
If both a global `custom_domain` and a per-request `CustomDomainHeader` are provided, the per-request value takes precedence.
355+
318356
## Feedback
319357

320358
### Contributing

0 commit comments

Comments
 (0)