Requirements
- C++17 or later
- libsodium: Ed25519 signature verification
- OpenSSL: SHA-256 and helpers
- libcurl: HTTPS requests
Installation
There is no central C++ package registry. Consume the official SDK from GitHub; AuthForgeCC/authforge-cpp (use a release tag under Releases).
Option A: FetchContent (CMake)
Pin a tag (for example v1.0.1) and link the authforge_sdk target:
Option B: Install prefix + find_package
Build and install the SDK, then point CMake at the prefix:
In your application:
Dependencies
Install development packages for libsodium, OpenSSL, and libcurl before configuring CMake. Examples:
- Linux (Debian/Ubuntu):
sudo apt install libsodium-dev libssl-dev libcurl4-openssl-dev
- macOS (Homebrew):
brew install libsodium openssl curl; set CMAKE_PREFIX_PATH if CMake does not find Homebrew prefixes.
- Windows: Use vcpkg for
libsodium, openssl, and curl, then pass -DCMAKE_TOOLCHAIN_FILE=.../vcpkg.cmake.
Quick start
Constructor parameters
ttlSeconds (grace period)
Requested session token lifetime in seconds for /auth/validate, passed as the 9th constructor parameter. This is the grace period: how long the app keeps running on the signed session without contacting AuthForge. Pass 0 (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 extend 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 true on success, false otherwise. On success, a background thread re-verifies the signed session locally during the grace period (and sends online check-ins if OnlineHeartbeat::On was passed).
Validate license (no session)
Same /auth/validate request and Ed25519 verification as Login, without persisting session fields on the client or starting the background thread. Does not invoke the failure callback or std::exit on error; inspect valid / errorCode instead.
Failure callback
If no callback is set (or the callback throws), the SDK calls std::exit(1).
If you don’t set an onFailure callback, the SDK terminates the process immediately via std::exit(1). Always set a callback in production.
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 by passing authforge::OnlineHeartbeat::On as the 4th constructor argument:
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. Pass an empty appSecret so the air-gapped binary does not contain the App Secret.
Failures call onFailure("offline_login_failed", &exc) with exc.what() set to the code and return false (never std::exit). Codes, in check order: bad_armor, bad_signature, unsupported_version, malformed_payload, wrong_app, expired, hwid_mismatch. client.VerifyLicenseFile(pathOrText) and the free function authforge::VerifyLicenseFile(text, appId, publicKeys, hwid) run the same checks without touching state and return a VerifyLicenseFileResult. Issued files cannot be revoked remotely; they stay valid until their own expiry. CreateActivationRequest() produces the .authforge-request the operator uploads; hostname is omitted unless includeMachineName is set. See Activation requests.
Migrating from "SERVER" / "LOCAL"
The legacy constructors taking a "SERVER" or "LOCAL" string as the 4th argument are deprecated but still work:
"LOCAL": drop the argument; the grace period is now the default.
"SERVER": pass authforge::OnlineHeartbeat::On instead.
Full example (game)
GitHub
Full source, changelog, and issues: AuthForgeCC/authforge-cpp