44package com .auth0 .client .mgmt ;
55
66import com .auth0 .client .mgmt .core .ClientOptions ;
7+ import com .auth0 .client .mgmt .core .CustomDomainInterceptor ;
78import com .auth0 .client .mgmt .core .Environment ;
89import com .auth0 .client .mgmt .core .OAuthTokenSupplier ;
910import java .util .HashMap ;
@@ -25,6 +26,8 @@ public class ManagementApiBuilder {
2526
2627 private OkHttpClient httpClient ;
2728
29+ private String customDomain = null ;
30+
2831 // Domain-based initialization fields
2932 private String domain = null ;
3033 private String clientId = null ;
@@ -107,6 +110,40 @@ public ManagementApiBuilder audience(String audience) {
107110 return this ;
108111 }
109112
113+ /**
114+ * Sets the custom domain for the Auth0-Custom-Domain header.
115+ * When configured, the header is automatically sent on whitelisted API endpoints
116+ * that generate user-facing links (email verification, password change, invitations, etc.).
117+ *
118+ * <p>The header is only sent to whitelisted endpoints:
119+ * <ul>
120+ * <li>{@code /jobs/verification-email}</li>
121+ * <li>{@code /tickets/email-verification}</li>
122+ * <li>{@code /tickets/password-change}</li>
123+ * <li>{@code /organizations/{id}/invitations}</li>
124+ * <li>{@code /users} and {@code /users/{id}}</li>
125+ * <li>{@code /guardian/enrollments/ticket}</li>
126+ * <li>{@code /self-service-profiles/{id}/sso-ticket}</li>
127+ * </ul>
128+ *
129+ * <p>Example:
130+ * <pre>{@code
131+ * ManagementApi client = ManagementApi.builder()
132+ * .domain("your-tenant.auth0.com")
133+ * .token("YOUR_TOKEN")
134+ * .customDomain("login.mycompany.com")
135+ * .build();
136+ * }</pre>
137+ *
138+ * @param customDomain The custom domain (e.g., "login.mycompany.com")
139+ * @return This builder for method chaining
140+ * @see CustomDomainHeader#of(String) for per-request custom domain overrides
141+ */
142+ public ManagementApiBuilder customDomain (String customDomain ) {
143+ this .customDomain = customDomain ;
144+ return this ;
145+ }
146+
110147 /**
111148 * Sets the timeout (in seconds) for the client. Defaults to 60 seconds.
112149 */
@@ -154,6 +191,10 @@ protected ClientOptions buildClientOptions() {
154191 for (Map .Entry <String , String > header : this .customHeaders .entrySet ()) {
155192 builder .addHeader (header .getKey (), header .getValue ());
156193 }
194+ if (this .customDomain != null ) {
195+ builder .addHeader (CustomDomainInterceptor .HEADER_NAME , this .customDomain );
196+ builder .addInterceptor (new CustomDomainInterceptor ());
197+ }
157198 setAdditional (builder );
158199 return builder .build ();
159200 }
0 commit comments