# Widget, let your customers connect their domains

> Let your customers connect domains inside your product.

Source: https://docs.customdomain.ai/docs/getting-started/widget

Use the widget when **your customers** own the domains and should connect them
**inside your product**. You never touch their DNS. The modal detects the
provider, offers the best [way to connect](/docs/concepts/glossary#ways-to-connect)
it can finish, and reports back.

[Open Widget in console](https://app.customdomain.ai/app/embed)

No customer domain to try it with yet? Make a [Sandbox](/docs/guides/test-mode)
application and follow the steps below with its `client_secret` and a name such as
`www.acme.test`. The widget runs end to end on a simulated DNS, with no card, no free
domain used and nothing billed.

## Have your coding agent do it

The **Install** tab on **Widget** in the console starts with **Hand it to your
coding agent**. **Copy prompt** gives you one block of text to paste into Claude
Code, Cursor, Codex or any agent that edits your project. It names your
application ID, the install guide, the SDK reference and the docs index
(`llms.txt`), picks up the server language and page framework you chose on the
tab, and lists the steps in order: the server route, the button, the result
handling. The agent shows you each change before it makes it.

The prompt never contains a secret. It tells the agent that the API key lives in
your server's environment, that you set it yourself, and that it must never ask
you to paste it into the chat or write it into code. Your application ID is the
only identifier in it, and that one is public.

### Mint a widget token on your server

Your server trades a credential for a short-lived widget token, and only that
token reaches the browser. If you signed up in the console (most customers),
create an API key on **API & SDK** with **Create key** (the **Install** tab's
**Get your API key** button opens the same form) and send it as the bearer to
`POST /v1/tokens`. You see the key once: store it as `CUSTOMDOMAIN_API_KEY`. This is what the **Install** tab on the **Widget** page generates
by default:

```bash
curl -X POST https://api.customdomain.ai/v1/tokens \
  -H "Authorization: Bearer $CUSTOMDOMAIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"application_id":"app_...","domain":"shop.acme.com"}'
# → 201 { "token": "eyJ…", "token_type": "Bearer", "expires_in": 900, "scope": "connect" }
```

If you created the application over the API, you have its `client_secret`
instead; send it in the body of the same `POST /v1/tokens`, with no bearer key. Both calls, the errors and the difference
between the two credentials are on [Widget tokens](/docs/authentication/widget-tokens).

`domain` binds the token to one hostname (recommended). Tokens last 15
minutes, so mint one per open and pass `getToken` (step 2) so a long manual
setup refreshes instead of stopping. The default scope, `connect`, runs the
connect flow and nothing else.

Mint it with the domain and your customer's `end_user_ref` too
(`"end_user_ref":"user_42"` beside `domain`) where you can. Some providers can be
signed in through a [secure sign-in](/docs/guides/secure-sign-in), a temporary
browser where your customer signs in to the provider (offered to selected
workspaces for now), and it runs only for a token bound to the domain and the end
user. If your platform asks the
customer for the domain first, mint the token after that. A token minted before
the domain is known still runs the whole flow; the widget then shows the manual
setup for those providers instead.

### Open the modal

```html
<script src="https://app.customdomain.ai/widget-assets/customdomain-sdk.js"></script>
<script>
  customdomain.open({
    applicationId: "app_...",
    token: "<widget JWT from step 1>",
    getToken: () => fetch("/api/customdomain-token", { method: "POST" })
      .then((r) => r.json()).then((d) => d.token), // your endpoint for step 1
    domain: "shop.acme.com",
    endUserRef: "user_42", // your id for this customer
    onSuccess: ({ domain }) => markConnected(domain),
    onClose: ({ lastStatus, error }) => log(lastStatus, error),
  });
</script>
```

`endUserRef` is *your* id for the customer: it is stored on the connection as
`end_user_ref`, shown in the console, and sent with every webhook as
`user_id`. Every
screen change fires `customdomain:step`; a failure fires `customdomain:error`
with a branchable `code`. Full options and events:
[Widget reference](/docs/widget-sdk/reference).

When the customer types a root domain (`acme.com`), the widget asks whether to
connect it with `www` (recommended), on its own, or as a subdomain instead;
pass `wwwRedirect` to decide for them. See [Root domains](/docs/dns/root-domains).

### What your customer will see, by provider

| Their DNS provider                                                                                                                 | The modal offers                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | They type                                                                                 |
| ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
| Cloudflare, DigitalOcean, DNSimple, Linode (Akamai Cloud), Netlify, WordPress.com                                                  | **Authorize with the provider** (OAuth). On the hosted service the permission is kept, encrypted, so records can be repaired, and the modal says so                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | nothing                                                                                   |
| Azure DNS, Dynadot, Unstoppable Domains                                                                                            | **Authorize with the provider** (Dynadot and Unstoppable Domains through their MCP servers; Dynadot needs MCP switched on in its API settings first). The permission is used once                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | nothing                                                                                   |
| Google Cloud DNS                                                                                                                   | **Sign in with Google Cloud**. Until Google finishes reviewing the app, Google may show a notice that it has not verified the app yet. The project ID and an access token are the other option                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | nothing, or the project ID and an access token                                            |
| Vercel                                                                                                                             | **Install CustomDomain™ on Vercel**, on the team that owns the domain                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | nothing                                                                                   |
| Porkbun                                                                                                                            | **Approve access at Porkbun** (API access must be on for the domain)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | nothing                                                                                   |
| NameSilo, Glauca Digital, Domain Chief                                                                                             | **One-click setup** at the provider, which sends them back when they approve                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | nothing                                                                                   |
| GoDaddy, Namecheap, Name.com, IONOS, Squarespace, Hover, Spaceship, Hostinger                                                      | **Secure sign-in** (offered to selected workspaces for now, and only where the token is bound to the domain and the end user): they sign in to the provider in a secure window. Where the provider allows it, a lasting API key is made and kept, so the domain stays connected through the provider's API. Where no key can be made, our software makes the changes on the provider's DNS page. A change that only adds records goes ahead by itself; one that replaces or removes a record is shown first and waits for their approval ([details](/docs/guides/secure-sign-in#review)). If the sign-in does not finish, or secure sign-in is not on for the workspace, the modal shows the records, as in the next row | their provider login, and a code if the provider asks for one (we never see the password) |
| OVHcloud, Route 53, Network Solutions, Wix, a site builder or shop that sold the domain (Shopify, Canva and more), everything else | **Add the records**, with *why* the automatic ways aren't available, the Name to type in their panel, step-by-step instructions for their provider (most providers and platforms have their own), and a live check of each record; or hand the job to an AI assistant, email it to whoever manages DNS, or (where your application turns on [DNS hosting](/docs/dns/managed-dns)) let you keep the domain working for them by moving its nameservers                                                                                                                                                                                                                                                                     | the records (about two minutes), or nothing                                               |
| Unknown provider                                                                                                                   | a provider picker, then the records                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | the records                                                                               |

This table is what `POST /v1/domains:check` returns as `rails`; the widget
reads it live, so you never have to maintain it. Which of the OAuth sign-ins
(DigitalOcean, Linode and Azure DNS among them) the hosted service has on is
confirmed per provider; see
[Managed connections](/docs/connect-flow/managed-connections). The widget shows
five of the [six ways to connect](/docs/concepts/glossary#ways-to-connect): a
sign-in with the provider, one-click setup, secure sign-in, the records to add,
and DNS hosting where your application offers it. The other way, an API key, is
for the console and the API.

### Records you supply

For records only you know (SES DKIM, a verification `TXT`), create the
connection **server-side first** (`POST /v1/connections`, then
`PUT /v1/connections/{id}/records` with your API key), and open the widget
for that domain: it shows *your* records. An email-only set (no edge record) is
verified and reported but **never served** and gets **no certificate**; that is
by design. [Bring your own records](/docs/dns/bring-your-own-records).

### After the modal closes

After a sign-in or one-click setup writes the records, the modal waits for DNS
to show them, which usually takes seconds. Past a minute it tells the customer
the wait is unusual and that they can close the window, because the domain
connects on its own as soon as DNS updates.

`onSuccess` fires when the domain is `live`. If the customer closes early,
the connection keeps being checked (`pending` never fails on its own); the
next open resumes it. A `failed` connection is recoverable in the modal
itself: the records stay on screen with the reason, and *Check now*
re-enters verification. If the customer emailed the instructions to someone
else, that person finishes from the link in the email (the modal reports
`FINISHED_SUCCESSFULLY_LINK_SHARED`). Subscribe to `connection.live` /
`connection.failed` webhooks (each with `user_id` and, when present,
`error_code` / `error_message`), and poll `GET /v1/connections/{id}` as the
fallback.

## Check that it works

When you have added the widget, the console checks that it opened on your site.
If it does not turn green, do these in order:

1. Make sure the widget is on the page you are looking at, and that your server creates the token in step 1.
2. Make sure your site's address is listed as an [allowed origin](/docs/widget-sdk/allowed-origins).
3. Reload the page and try again.

## Don't

> * Don't gate your UI on `setupType === "automatic"`; read `rails`.
> * Don't send your API key or client secret from the page; the widget JWT is
>   the browser credential.
> * Don't call `customdomain.open()` for `*.vercel.app`-style hosts; the
>   pre-flight refuses them with `platform_subdomain`.
