Skip to content

Added field domainMetadata for custom domain endpoints #1109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tanya732
Copy link
Contributor

@tanya732 tanya732 commented May 14, 2025

Changes

Added changed in below endpoints -

Path HTTP Method Method Name
/custom-domains GET getAll
/custom-domains POST create
/custom-domains/{id} GET get
/custom-domains/{id} DELETE delete
/custom-domains/{id} PATCH update
/custom-domains/{id}/verify POST verify

Introduced CustomDomainHeader function:

  1. Adds a custom domain header (auth0-custom-domain) to requests based on a whitelist of API paths.
  2. Includes validation for whitelisted paths using pre-compiled regex patterns.

Added helper functions:

  1. compileWhitelistedPathPatterns - Compiles regex patterns for whitelisted API paths.
  2. isCustomDomainPathWhitelisted - Validates if a given path matches any whitelisted pattern.

Management API Updates

  1. Removed compatible option for TLS policies, leaving only the recommended option, which includes TLS 1.2. Updated comments to reflect this change.

  2. Added support for domain_metadata on these interfaces PatchCustomDomainsByIdRequest, PostCustomDomainsRequest, PostCustomDomains201Response, PostVerify200Response

  3. verification_method will be deprecated soon

Updated interface GetCustomDomainsRequest:
Added optional filters:

domain_metadata_filter
domain_name_filter.

Updates to management-client-options.ts:
Custom Headers:
Added an optional headers property to the ManagementClientOptions interface. This allows users to specify custom headers as a Record<string, string>.

References

Please include relevant links supporting this change such as a:

  • support ticket
  • community post
  • StackOverflow post
  • support forum thread

Manual testing

Securely store your Client ID, Client Secret, and Management API token.
Install the SDK: npm install auth0

var auth0 = new ManagementClient({
domain: '{YOUR_TENANT_AND REGION}.auth0.com',
clientId: '{YOUR_CLIENT_ID}',
clientSecret: '{YOUR_CLIENT_SECRET}',
});

const getAllResp = await auth0.customDomains.getAll()

const getResp = await auth0.customDomains.get({id : "custom_domain_id"})

const createPayload: PostCustomDomainsRequest = {
  domain: "test.dummy.com",
  type: "auth0_managed_certs",
}
const createCustomDomain = await auth0.customDomains.create(createPayload);

const updatePayload: PatchCustomDomainsByIdRequest = {
  domain_metadata: {
    "dummy1": "value1",
    "dummy2": "value2",
  }
}

const id: PatchCustomDomainsByIdOperationRequest = {
  id: "custom_domain_id"
}
const updateCustomDomain = await auth0.customDomains.update(id, updatePayload);

const deletePayload: DeleteCustomDomainsByIdRequest = {
   id: "custom_domain_id"
}
const deleteCustomDomain = await auth0.customDomains.delete(deletePayload);

const verifyPayload: PostVerifyRequest = {
  id: "custom_domain_id"
}
const verifyCustomDomain = await auth0.customDomains.verify(verifyPayload);


You can configure the SDK to send an auth0-custom-domain header. This is useful in scenarios where Auth0 needs to know the original custom domain a request was intended for, especially for certain email templates or universal login flows.

This option sets a custom domain header globally for all requests made by a management client instance. The header is only applied if the request path is whitelisted (e.g., /api/v2/users, /api/v2/jobs/verification-email).

const token = "token"
const auth0 = new ManagementClient({
    domain: '{domain}',
    token: token,
    headers: {
      'auth0-custom-domain': '{custom_domain}'
    }
});

try {

    const reqBody : PostVerificationEmailRequest = {
      "user_id":"{user_id}", // Replace with your connection ID
    };

    // Call the API with the custom domain header
    const verificationEmail = await auth0.jobs.verifyEmail(
      reqBody);

  } catch (error) {
    console.error("Error creating user:", error);
  }

This option sets or overrides the auth0-custom-domain header for a specific API request. It takes precedence over any globally set header and applies regardless of whether the endpoint is whitelisted for the global option.

const token = "token"
const auth0 = new ManagementClient({
    domain: '{domain}',
    token: token,
    headers: {
      'auth0-custom-domain': '{custom_domain}'
    }
});

try {

    const reqBody : PostVerificationEmailRequest = {
      "user_id":"{user_id}", // Replace with your connection ID
    };

    // Call the API with the custom domain header
    const verificationEmail = await auth0.jobs.verifyEmail(
      reqBody, CustomDomainHeader("{custom_domain}"));

  } catch (error) {
    console.error("Error creating user:", error);
  }

Testing

Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.

  • This change adds unit test coverage
  • This change adds integration test coverage

Checklist

@tanya732 tanya732 marked this pull request as ready for review May 15, 2025 07:00
@tanya732 tanya732 requested a review from a team as a code owner May 15, 2025 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant