An admin API for your licenses: support without opening the dashboard

We've added an admin REST API to our licensing system. How it works, how we protect it with two layers, and why it does exactly what the dashboard does and nothing more.

Until this week, everything we did with our apps’ licenses went through the admin dashboard: looking up a customer, resending a key, freeing a device or checking the day’s sales. The dashboard works well, but you have to open the browser, sign in and click around. When you want to automate something, or check it from another tool, it falls short.

So we’ve added an admin REST API to the same Worker that sells and activates the licenses. This post covers what it does, how we protect it and what we’ve deliberately left out.

The same as the dashboard, no more and no less

The first decision was not to invent anything. The API has no business logic of its own: it calls the same functions the dashboard uses. If the dashboard won’t let you revoke a license without a reason, neither will the API. If the dashboard won’t let you create a paid license by hand, neither will the API.

That saves us from the classic problem of two paths that do almost the same thing and drift apart over time. And every change lands in the same history as the dashboard’s, with the name of the token that made it.

There are 17 operations today, in three groups:

  • Read: list the apps, search licenses (by email, key or Stripe ID), see a license with its devices and history, see a customer and get a sales summary for a period.
  • Support: resend the key by email, free a device, change the number of devices, set a note and reset the device-change counter.
  • Manage: create a free or lifetime license (with a required note explaining why it exists), reveal a key, revoke, reactivate and move a license to another email.

Everything is JSON. Amounts are in cents. Errors always carry a stable code (not_found, confirm_required, rate_limited…) so you decide on that, not on the message text.

Two layers before anything is touched

An API that can revoke licenses or see customer emails has to be locked down properly. Ours has two layers, and you need both.

The first is Cloudflare Access. In front of the API there’s a Zero Trust application that only lets through requests carrying one specific service token. Without it, the request never reaches our code: Cloudflare answers 401 and that’s that. On top of that, the Worker checks the signature of the JWT that Access adds, so finding another way in isn’t enough either.

The second is our own token, created in the dashboard, starting with cvl_live_ or cvl_test_ depending on the environment. The token is shown only once; the database stores its hash, not the token. Each one has:

  • Tiered permissions: read, support, manage and personal data. A read token doesn’t even see the support operations.
  • Expiry: 30, 90 or 365 days, or none if you choose so.
  • IP restriction: by default it only works from the IPs you use to reach the dashboard.
  • Rate limit: 30 requests per minute per IP.

If a token leaks, you revoke it from the dashboard and it stops working immediately.

Personal data only when asked for

This part mattered to us in particular. A token without the personal-data permission gets emails masked (a***@example.com) and never sees IPs, device names or the technical details of activations. It can still do support: searching by email works even though the answer comes back masked.

The full data only comes out with a token that has that permission. That way, what we use every day to check sales or resend keys isn’t spreading customer data around.

Confirming what can’t be undone

Revoking a license or moving it to another email requires sending "confirm": true explicitly. A "yes", a 1 or anything close won’t do: it’s the boolean true or nothing happens. And reactivating a license revoked by a refund asks for a second confirmation, because reactivating it means giving away what was refunded.

There are also things the API doesn’t do, and that’s not an oversight. It doesn’t refund or cancel in Stripe: money is handled in Stripe. And creating a license by hand doesn’t send any email; if you want the customer to get it, tell them yourself or use “resend key”.

What it looks like in practice

With both credentials in place, finding a customer’s licenses is one line:

curl -H "Authorization: Bearer $TOKEN" \
  -H "CF-Access-Client-Id: $CF_ID" -H "CF-Access-Client-Secret: $CF_SECRET" \
  "https://<your-worker>/api/admin/v1/licenses?q=ana@example.com"

We tested it first in the test environment and then in production the same way: with everything, it returns the data; without the Cloudflare headers, 401; with Cloudflare but without our token, 401 too.

From here to the AI assistant

The API has a second face: the same 17 operations are also offered as tools on an MCP server, so an AI assistant can do support for you. That’s the next post: how our MCP server for managing licenses works.

All of this runs today in the licensing system behind our apps. With OwnLicense we want any maker to have it in their own Cloudflare account. If you’re interested, have a look at the SDKs and the API or join the waitlist.

  • #Licensing
  • #API
  • #Cloudflare
  • #Security

← All posts · RSS feed

Want it in your own account?

Ask for the private beta with your GitHub username: it's free, by invitation, and we review every request by hand.