How to validate license keys in an Electron app

Short answer

To validate license keys in an Electron app, call Ruba’s activate endpoint once per device and its validate endpoint when the app starts or a paid action runs, from the main process, always sending your organization ID. Ruba issues the keys and hosts the check, and pays you to your own bank. What happens when a check fails is yours to design.

The flow in plain steps

A Ruba license key can allow 1 to 50 activations, and a validate call tells your app if a key is still good. Tanvir in Chattogram built a bulk file renamer with Electron. A buyer pays on a Ruba checkout link, receives a key like RENAME-…, and pastes it into the app. Then the app must decide: is this key real, and is it allowed on this computer?

From key to unlocked app
  1. First runActivateLabel the device. Store the activation ID.
  2. Each launchValidateSend key and activation ID.
  3. SuccessUnlock featuresCache the result carefully.
  4. FailureLock or explainYour design decides.
Figure 1Based on Ruba’s license key docs. Run these calls in Electron’s main process, not in the renderer.

Activate a device

The activate call needs the key, your organization ID, a label for the device and optional conditions. The conditions you register here must be sent again at validation.

main process, TypeScript
const API = 'https://api.getruba.com' // use https://sandbox-api.getruba.com in tests

export async function activate(key: string, label: string) {
  const response = await fetch(`${API}/v1/customer-portal/license-keys/activate`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      key,
      organization_id: ORGANIZATION_ID,
      label,
      conditions: { major_version: 1 },
    }),
  })
  if (!response.ok) throw new Error('Activation failed')
  return response.json()
}
Figure 2Adapted from Ruba’s docs. Replace ORGANIZATION_ID with yours. Treat any non-success response as a failed activation.

Validate on launch

Validation takes the key, your organization ID, the activation ID and the same conditions. Always check the organization ID, so a valid key from another seller’s shop cannot unlock your app. If you sell several License keys benefits, match the benefit ID too.

main process, TypeScript
export async function isLicensed(key: string, activationId: string) {
  const response = await fetch(`${API}/v1/customer-portal/license-keys/validate`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      key,
      organization_id: ORGANIZATION_ID,
      activation_id: activationId,
      conditions: { major_version: 1 },
    }),
  })
  return response.ok
}
Figure 3Adapted from Ruba’s docs. Read the API reference for the full response fields you want to use.

The installer goes to the buyer by a private link that lasts 60 minutes, and the file is checked for malware first.

Decisions that are yours

Ruba does
Issue a unique key per buyer
Enforce expiry and activation limits
Host the validation check
Your app does
Call the endpoints from the main process
Decide how long to trust a past check offline
Handle a failed check kindly
Figure 4From Ruba’s docs, plus general good practice.
Before you ship0 of 4
Tap each line you already have.
Figure 5Tap each line when it is done.

What to do next

Create a product, attach a License keys benefit and test in the sandbox. Then see the early-access deal. Ruba charges 4% + $0.50 per sale with no monthly fee. Related: selling a desktop app with license keys.

Validate on launch, and handle the offline case. Skip the company and the monthly fee: neither is needed. The rate for your Electron app is 4% + $0.50 per sale, locked once you are approved in early access, for as long as the account stays open and in good standing. A fee Ruba never told you about is refunded, and Ruba pays you $100. Terms apply. See the early-access deal.

Questions people ask

Which endpoints do I call?

The customer portal has endpoints for license keys: activate and validate, at /v1/customer-portal/license-keys/activate and /validate on api.getruba.com. They take the key and your organization ID, and they need no access token in the app.

What must I always check?

The organization ID, so a valid key from another Ruba organization cannot be accepted. If your organization sells several License keys benefits, also match the benefit ID to the capability you expect.

How do I limit a key to a few computers?

Set an activation limit from 1 to 50 on the benefit. Create an activation with a label when the app starts on a new device, then send the activation ID when you validate.

What about working offline?

Ruba hosts online validation. If your app must work offline, decide how long to trust the last successful check, and store it carefully. That part is your design.

Does Ruba store the activation for me?

Ruba records activations. Your app stores the activation ID it gets back, so it can validate later.

Sources

We check these when we update this guide. Rules can change, so check them yourself before you decide.

A note from FaizanHi, I’m Faizan, the founder of Ruba. I built it so people anywhere, from Pakistan, India and Bangladesh to the UK, the EU and the US, can sell software to the world and get paid at home.I wrote these guides to be as fair as I can. But I built Ruba, so I’m about as neutral as a parent at a school play. That’s why every fact has a source you can check.
Early access is live.

Sellers approved now keep 4% + $0.50 per sale locked for as long as they sell, plus +$100 if we ever charge a fee we never told you about. No company and no monthly fee. You are paid to a bank in your own name, in PKR, INR, BDT or 51 other currencies, whenever you ask, from $10. A payout costs $2 up to $200.

Applying is not approval. Terms apply.
All guides

Can’t find your country or currency? Email support@getruba.com.

This guide is general information, not legal, tax or financial advice. Other companies named here set their own rules, which can change. Check their websites before you decide.