Skip to main content

Requirements

  • Node.js 18.0 or later
  • No runtime dependencies beyond Node.js built-ins

Installation

Install from npm as @authforgecc/sdk:
The package ships authforge.mjs and TypeScript declarations (authforge.d.ts).
Prefer a single file in-repo? Copy authforge.mjs from GitHub. The npm package is recommended for versioning and updates.

TypeScript

Use the same import as JavaScript; types resolve from the package:

Quick start

Constructor parameters

ttlSeconds (grace period)

Requested session token lifetime in seconds for /auth/validate. This is the grace period: how long the app keeps running on the signed session without contacting AuthForge. Pass null (or omit) to accept the server default of 24 hours. The server clamps to [3600, 604800] (1 hour to 7 days). The requested TTL is preserved across heartbeat refreshes, and apps relying on the grace period alone can stretch their window up to 7 days.

Billing

  • Each successful login() or validateLicense() costs 1 credit (one /auth/validate debit).
  • The grace period is free: local session re-verification makes no network calls and consumes no credits.
  • Online check-ins (if enabled) cost 1 credit per 10 successful heartbeats (billed on every 10th call).
  • With online check-ins, revocations take effect on the next check-in regardless of interval; without them, at session expiry.

Login

Returns Promise<boolean>. It resolves to true if authentication succeeded, false otherwise. On success, the SDK starts a background timer that re-verifies the signed session locally during the grace period (and sends online check-ins if onlineHeartbeat: true).

Validate license (no session)

Same /auth/validate request and Ed25519 verification as login, without mutating the client’s stored session or starting the background timer. Use this for bots and repeated checks; use login when you want a long-lived session. Successful results may also include sessionExpiresAt, licenseExpiresAt (null for lifetime keys), maxHwidSlots, hwidCount, and licenseLabel when present in the signed payload; the decoded payload is always available as sessionData.

Failure callback

If authentication fails, an online check-in fails, or the session expires, the SDK calls your onFailure callback. If no callback is set (or the callback throws), the SDK exits the process.
If you don’t set onFailure, the SDK terminates the process immediately on any failure. Set a callback in production for graceful shutdown.

Reading variables

After successful login, app variables and license variables are available on the client:

Grace period and online check-ins

By default, the app runs through the grace period after activation: the SDK re-verifies the signed session locally, makes no network calls, and stops when the session expires. Opt in to online check-ins for fast revocation and concurrent-use detection:
See Online Check-ins for a detailed comparison.

Offline license files (.authforge)

For machines that never connect to the internet, the operator mints a signed offline license file in the dashboard or Developer API (1 credit). The SDK verifies it locally with your public key and the machine HWID; no network, no check-ins, and online login() is untouched. Omit appSecret so the air-gapped binary does not contain the App Secret.
Failures call onFailure("offline_login_failed", new Error(code)) and return false (never process.exit). Codes, in check order: bad_armor, bad_signature, unsupported_version, malformed_payload, wrong_app, expired, hwid_mismatch. client.verifyLicenseFile(pathOrText) and the exported verifyLicenseFile({ file, appId, publicKey, hwid }) run the same checks without touching state. Issued files cannot be revoked remotely; they stay valid until their own expiry. createActivationRequest() / writeActivationRequest(path) produce the .authforge-request the operator uploads; hostname is omitted unless includeMachineName: true. See Activation requests.

Migrating from heartbeatMode

heartbeatMode: "LOCAL" / "SERVER" is deprecated but still accepted:
  • heartbeatMode: "LOCAL": remove the option; the grace period is now the default.
  • heartbeatMode: "SERVER": use onlineHeartbeat: true instead.

Full example

GitHub

Full source, changelog, and issues: AuthForgeCC/authforge-node