SDK examples
The REST API works with any language. C++ is the maintained reference client; the runnable JavaScript, Python and C# examples use the same endpoints directly.
Get the SDK and runnable examples on GitHub.
Choose your language
| Language | Local source | Run / build |
|---|---|---|
| C++17 | sdk/cpp/examples/main.cpp | cmake --build build --config Release |
| JavaScript | sdk/examples/javascript/main.mjs | node main.mjs |
| Python 3 | sdk/examples/python/main.py | python3 main.py |
| C# / .NET 8 | sdk/examples/csharp/Program.cs | dotnet run |
Configure the examples
AUTHIX_URL=https://authix.top
AUTHIX_LICENSE_KEY=your-license-key
AUTHIX_HWID=your-stable-64-character-sha256-hashSet these as process environment variables using your shell or IDE. The examples read them without printing them. JavaScript needs Node 20+; Python uses only its standard library; C# uses .NET HttpClient. Each endpoint page includes copyable requests in all three languages and cURL.
Production integration
These REST examples illustrate activation, validation, heartbeat, entitlements and deactivation. For production loaders, add Ed25519 response proof verification, configured HMAC signing and session-bound binary delivery. See SDK security and loader delivery. Do not embed dashboard bearer tokens in client applications.
JavaScript / Node.js
Set the environment variables above, then run:
node sdk/examples/javascript/main.mjs// Transport example. Production loaders must verify Ed25519 serverProof and
// implement the product's configured request signing before trusting responses.
const base = new URL(process.env.AUTHIX_URL || 'https://authix.top');
if (base.protocol !== 'https:' && !['localhost', '127.0.0.1'].includes(base.hostname)) {
throw new Error('AUTHIX_URL must use HTTPS');
}
const licenseKey = process.env.AUTHIX_LICENSE_KEY;
const hwidHash = process.env.AUTHIX_HWID;
if (!licenseKey || !/^[a-f0-9]{64}$/i.test(hwidHash || '')) {
throw new Error('Set AUTHIX_LICENSE_KEY and AUTHIX_HWID (stable SHA-256 device identity)');
}
async function request(action, extra = {}) {
const response = await fetch(new URL(`/api/v1/sdk/${action}`, base), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ licenseKey, hwidHash, appVersion: '1.0.0', ...extra }),
signal: AbortSignal.timeout(15000),
});
const result = await response.json();
if (!response.ok || !result.success) {
throw new Error(`Request failed: ${response.status} ${result.error?.code || 'UNKNOWN'}`);
}
return result.data;
}
await request('activate');
try {
const validation = await request('validate');
if (!validation.valid) throw new Error('License is not valid');
await request('heartbeat');
await request('entitlements');
console.log('Activation, validation, heartbeat and entitlements succeeded.');
} finally {
await request('deactivate');
}
Python 3
Set the environment variables above, then run:
python3 sdk/examples/python/main.py"""Transport example. Production clients must verify Ed25519 serverProof and
implement any product-required request signing before trusting responses."""
import json
import os
import re
from urllib.error import HTTPError
from urllib.parse import urlsplit
from urllib.request import Request, urlopen
def run():
base = os.getenv("AUTHIX_URL", "https://authix.top").rstrip("/")
origin = urlsplit(base)
if origin.scheme != "https" and origin.hostname not in ("localhost", "127.0.0.1"):
raise ValueError("AUTHIX_URL must use HTTPS")
key = os.getenv("AUTHIX_LICENSE_KEY")
hwid = os.getenv("AUTHIX_HWID", "")
if not key or not re.fullmatch(r"[a-fA-F0-9]{64}", hwid):
raise ValueError("Set AUTHIX_LICENSE_KEY and AUTHIX_HWID (stable SHA-256 device identity)")
def request(action):
body = json.dumps({"licenseKey": key, "hwidHash": hwid, "appVersion": "1.0.0"}).encode()
req = Request(base + "/api/v1/sdk/" + action, data=body,
headers={"Content-Type": "application/json"}, method="POST")
try:
with urlopen(req, timeout=15) as response:
result = json.load(response)
except HTTPError as error:
raise RuntimeError(f"Request failed: HTTP {error.code}") from None
if not result.get("success"):
raise RuntimeError("Request failed: " + result.get("error", {}).get("code", "UNKNOWN"))
return result["data"]
request("activate")
try:
if not request("validate").get("valid"):
raise RuntimeError("License is not valid")
request("heartbeat")
request("entitlements")
print("Activation, validation, heartbeat and entitlements succeeded.")
finally:
request("deactivate")
if __name__ == "__main__":
run()
C# / .NET 8
Set the environment variables above, then run:
dotnet run --project sdk/examples/csharp// Transport example. Production clients must verify Ed25519 serverProof and
// implement product-required request signing before trusting responses.
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.RegularExpressions;
var baseUrl = new Uri(Environment.GetEnvironmentVariable("AUTHIX_URL") ?? "https://authix.top");
if (baseUrl.Scheme != "https" && !baseUrl.IsLoopback)
throw new InvalidOperationException("AUTHIX_URL must use HTTPS");
var key = Environment.GetEnvironmentVariable("AUTHIX_LICENSE_KEY");
var hwid = Environment.GetEnvironmentVariable("AUTHIX_HWID") ?? "";
if (string.IsNullOrEmpty(key) || !Regex.IsMatch(hwid, "^[a-fA-F0-9]{64}$"))
throw new InvalidOperationException("Set AUTHIX_LICENSE_KEY and AUTHIX_HWID (stable SHA-256 device identity)");
using var client = new HttpClient { BaseAddress = baseUrl, Timeout = TimeSpan.FromSeconds(15) };
async Task<JsonElement> Request(string action)
{
using var response = await client.PostAsJsonAsync("/api/v1/sdk/" + action,
new { licenseKey = key, hwidHash = hwid, appVersion = "1.0.0" });
response.EnsureSuccessStatusCode();
using var result = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
if (!result.RootElement.GetProperty("success").GetBoolean())
throw new InvalidOperationException("Request failed");
return result.RootElement.GetProperty("data").Clone();
}
await Request("activate");
try
{
if (!(await Request("validate")).GetProperty("valid").GetBoolean())
throw new InvalidOperationException("License is not valid");
await Request("heartbeat");
await Request("entitlements");
Console.WriteLine("Activation, validation, heartbeat and entitlements succeeded.");
}
finally { await Request("deactivate"); }