C# SDK
Licensr.Sdk wraps the licensing API: validation, seat/domain activation, offline EdDSA token verification, and hosted checkout. Targets netstandard2.1 and net8.0; async-first with System.Text.Json source generation throughout so it stays IL2CPP-safe. Its only runtime dependency is BouncyCastle.Cryptography — pure managed code, no P/Invoke — for offline EdDSA verification, mirroring the JS/TS SDK's single dependency on jose for the same job.
Paste this into Claude Code, Cursor, or a similar tool and it can do the integration for you.
Add Licensr license checks to this project with the C# SDK.
Follow https://docs.licensr.app/sdks/dotnet and ask me for any value you need.
Keep secrets in environment variables on my server, never in code that ships to customers.
Which hosts can load it
The SDK needs a host on .NET Core 3.0+ / .NET 5+, or Unity 2021.2+. That covers cTrader, Revit and AutoCAD 2025+, and Rhino 8.
It does not load in .NET Framework 4.8 hosts: NinjaTrader 8, Revit and AutoCAD 2024 and earlier, and Rhino 7. For those, make the plain web calls yourself with HttpClient. The any-language guide shows how.
Install
NuGet (.NET desktop/server, Godot's Mono backend, cTrader plugins):
dotnet add package Licensr.Sdk
Unity (two steps):
- Package Manager → Install package from git URL:
https://github.com/tekunodev/licensr-dotnet.git?path=upm
- Install BouncyCastle.Cryptography as well (e.g. NuGetForUnity). It is not bundled, so it does not clash with other assets that already ship it. Offline verify will not work until this assembly is in the project.
Quickstart
using Licensr.Sdk;
var client = new LicensrClient(new LicensrClientConfig
{
ApiKey = "pk_live_...", // safe to embed in a distributed build — see the embedded-key doctrine below
PluginSlug = "my-plugin",
});
var result = await client.ValidateAsync(new ValidateRequest { LicenseKey = userEnteredKey });
if (result.Valid)
{
UnlockFullFeatures();
}
else if (result.Entitlement == Entitlement.Limited)
{
UnlockDegradedMode(); // perpetual-fallback: expired, but the plan grants a limited tier
}
The result keeps what you act on at the top level: Valid, Status (why, for your message), Entitlement and FeatureFlags. Plan and limit details are grouped under result.License (PlanId, ActivationMode, MaxSeats, MaxDomains, SeatsInUse, ExpiresAt). They are for display only; never use them to decide whether to unlock.
See embedded-key doctrine. Methods return Task<T> — await them, or in a Unity coroutine use yield return new WaitUntil(() => task.IsCompleted) (or .AsUniTask() with UniTask).
API
Every method throws on failure — see Errors.
| Method | Wraps | Notes |
|---|---|---|
client.ValidateAsync(new ValidateRequest {LicenseKey}) | POST /v1/license/validate | Always read Valid/Entitlement; never branch on HTTP status — an unknown key returns 200 {valid: false}, not 404. |
client.TokenAsync(new ValidateRequest {LicenseKey}) | POST /v1/license/token | Same check as ValidateAsync, plus a short-lived signed offline token. See Offline verification. |
client.ActivateAsync(new ActivateRequest {...}) | POST /v1/license/activate | ActivationType is Seat (per-machine) or Domain, fixed by the plugin's configured mode. |
client.DeactivateAsync(new DeactivateRequest {...}) | POST /v1/license/deactivate | Frees a seat/domain slot. |
client.ActivationsAsync(new ActivationsRequest {LicenseKey}) | GET /v1/license/activations | Lists every current activation. |
client.CheckoutAsync(new CheckoutRequest {...}) | POST /v1/billing/checkout | Returns CheckoutUrl — direct the user there. Requires a key with the checkout scope. |
With a server test key (srv_test_…) from your server, set TestClock = true on CheckoutRequest to put the buyer on a Stripe test clock you can fast-forward to try renewals; the result returns its id as TestClockId.
Client options
new LicensrClientConfig
{
ApiKey = "pk_live_...",
PluginSlug = "my-plugin",
BaseUrl = "https://api.licensr.app", // default; override for self-hosted/staging
DeviceId = stableHwid, // buckets rate limits per installation instead of per key — see Hardware/device IDs below
Origin = "app://my-plugin", // rarely needed — set client type Native in the admin UI
TimeoutMs = 10_000,
Retry = new RetryOptions { MaxRetries = 2, BaseDelayMs = 300, MaxDelayMs = 5000 }, // network errors / 429 / 5xx, exponential backoff + jitter, honors Retry-After
Transport = myCustomTransport, // bring your own HTTP stack — see HTTP transport below
};
Events
client.Validated += (_, result) => Console.WriteLine($"validated: {result.Valid}");
client.Retry += (_, args) => Console.WriteLine($"retrying {args.Method}, attempt {args.Attempt} in {args.DelayMs}ms");
client.Error += (_, args) => ReportToCrashlytics(args.Method, args.Exception);
Available events: Validated, Activated, Deactivated, TokenIssued, Retry, Error.
Offline verification
client.TokenAsync() mints an EdDSA-signed JWT whose claims mirror ValidateAsync()'s response. Verify it fully offline (no network beyond the first JWKS fetch, cached for the process lifetime):
using Licensr.Sdk.Offline;
var token = await client.TokenAsync(new ValidateRequest { LicenseKey = licenseKey });
var claims = await OfflineTokenVerifier.VerifyAsync(
token.Token,
token.Details.JwksUrl,
new VerifyOfflineTokenOptions { PluginSlug = "my-plugin" });
if (!claims.Valid)
{
// signed and unexpired, but this license is not entitled
}
A token minted with a test key (pk_test_…) is refused, because test and live tokens are signed with the same key. In a test build, pass new VerifyOfflineTokenOptions { AllowTestTokens = true }.
Set PluginSlug = "my-plugin" in the same options too: every product in your organization signs with the same key, so without it a token for one of your products also unlocks another.
Offline tokens carry no revocation signal — they prove the token was genuinely issued and hasn't expired, not that the license is still active right now. Re-validate online before Exp.
To boot fully offline (no network at all, e.g. on first launch before any successful TokenAsync call), save the public keys with OfflineTokenVerifier.FetchJwksAsync while you are online and pass that JSON back as Jwks. The address alone still downloads the keys. Persist the token with the IOfflineTokenStore interface (InMemoryOfflineTokenStore is included, but doesn't survive a restart — back it with a config file, PlayerPrefs, or your platform's keychain).
Errors
| Exception | When |
|---|---|
LicensrApiException | Non-2xx response. Has Status, Code (matches the documented error codes), Message, and RetryAfterSeconds. Branch on Code, not Message — the message is for humans. |
LicensrNetworkException | The request never got a response (network failure, timeout, retries exhausted). |
LicensrTokenVerificationException | OfflineTokenVerifier.VerifyAsync rejected a bad signature, wrong algorithm, an expired/not-yet-valid token, or a test-key token. |
Hardware/device IDs
This SDK doesn't compute a hardware ID itself — a general-purpose netstandard2.1 library has no portable way to do that, and Unity already provides one:
var config = new LicensrClientConfig
{
ApiKey = "pk_live_...",
PluginSlug = "my-plugin",
DeviceId = SystemInfo.deviceUniqueIdentifier, // Unity — reuse the same value for ActivateRequest.Identifier
};
For non-Unity .NET desktop apps, generate and persist your own stable identifier (a GUID written to a config file on first run is sufficient) and pass it as both DeviceId and the seat ActivateRequest.Identifier.
HTTP transport
The default HttpClientTransport (backed by System.Net.Http.HttpClient) works on every Unity IL2CPP platform except WebGL, where HttpClient isn't supported. Implement IHttpTransport (one method, SendAsync) with a UnityWebRequest-backed transport for WebGL and pass it as LicensrClientConfig.Transport.
Source & issues
Source lives in github.com/tekunodev/licensr-dotnet, mirrored from this monorepo's sdks/dotnet/. File issues and PRs there.