Requirements
- C++17 or later
- OpenSSL — for HMAC-SHA256 and SHA-256
- libcurl — for HTTPS requests
Installation
Download authforge_sdk.h and authforge_sdk.cpp from the repository and add both files to your project:
Git clone
Direct download
git clone https://github.com/AuthForgeCC/authforge-cpp.git
cp authforge-cpp/authforge_sdk.h ./your-project/
cp authforge-cpp/authforge_sdk.cpp ./your-project/
Download both files from github.com/AuthForgeCC/authforge-cpp and place them in your project directory.
Linking
Add OpenSSL and libcurl to your build:
find_package(OpenSSL REQUIRED)
find_package(CURL REQUIRED)
target_sources(your_app PRIVATE authforge_sdk.cpp)
target_link_libraries(your_app PRIVATE OpenSSL::SSL OpenSSL::Crypto CURL::libcurl)
g++ -std=c++17 main.cpp authforge_sdk.cpp -lssl -lcrypto -lcurl -o your_app
cl /std:c++17 /EHsc main.cpp authforge_sdk.cpp /I"path\to\openssl\include" /I"path\to\curl\include" /link libssl.lib libcrypto.lib libcurl.lib
Quick start
#include "authforge_sdk.h"
#include <iostream>
#include <string>
int main() {
authforge::AuthForgeClient client(
"YOUR_APP_ID",
"YOUR_APP_SECRET",
"SERVER"
);
std::string key;
std::cout << "Enter license key: ";
std::getline(std::cin, key);
if (client.Login(key)) {
std::cout << "Authenticated!" << std::endl;
// Your app logic here — heartbeats run in the background
} else {
std::cout << "Invalid license key." << std::endl;
return 1;
}
return 0;
}
Constructor parameters
authforge::AuthForgeClient client(
"app_id", // Required — from dashboard
"app_secret", // Required — from dashboard
"SERVER", // Required — "SERVER" or "LOCAL"
900, // Optional — heartbeat interval in seconds (default: 900)
"https://auth.authforge.cc", // Optional — API base URL
on_failure_callback, // Optional — void(const std::string& reason, const std::exception* ex)
15 // Optional — HTTP timeout in seconds
);
Login
bool success = client.Login(license_key);
Returns true on success, false otherwise. Starts background heartbeats on success.
Failure callback
If no callback is set (or the callback throws), the SDK calls std::exit(1).
#include "authforge_sdk.h"
#include <iostream>
void on_failure(const std::string& reason, const std::exception* ex) {
if (reason == "login_failed") {
std::cerr << "Login failed." << std::endl;
} else if (reason == "heartbeat_failed") {
std::cerr << "Heartbeat failed — saving state." << std::endl;
save_application_state();
}
if (ex) {
std::cerr << " Detail: " << ex->what() << std::endl;
}
}
int main() {
authforge::AuthForgeClient client(
"YOUR_APP_ID",
"YOUR_APP_SECRET",
"SERVER",
900,
"https://auth.authforge.cc",
on_failure
);
// ...
}
If you don’t set an onFailure callback, the SDK terminates the process immediately via std::exit(1). Always set a callback in production.
Heartbeat modes
// SERVER mode — pings the API every interval
authforge::AuthForgeClient client("...", "...", "SERVER");
// LOCAL mode — verifies locally, re-validates when prepaid block expires
authforge::AuthForgeClient client("...", "...", "LOCAL");
See Heartbeat Modes for a detailed comparison.
Full example (game)
#include "authforge_sdk.h"
#include <iostream>
#include <string>
#include <atomic>
std::atomic<bool> g_licensed{false};
void on_auth_failure(const std::string& reason, const std::exception* ex) {
std::cerr << "[AuthForge] " << reason;
if (ex) std::cerr << ": " << ex->what();
std::cerr << std::endl;
g_licensed.store(false);
// Don't exit here — let the game loop handle shutdown gracefully
}
int main() {
authforge::AuthForgeClient client(
"YOUR_APP_ID",
"YOUR_APP_SECRET",
"SERVER",
900,
"https://auth.authforge.cc",
on_auth_failure
);
std::string key;
std::cout << "Enter license key: ";
std::getline(std::cin, key);
if (!client.Login(key)) {
std::cerr << "Invalid license key." << std::endl;
return 1;
}
g_licensed.store(true);
std::cout << "Licensed. Starting game..." << std::endl;
// Game loop
while (g_licensed.load()) {
// Update game state
// Render frame
// If g_licensed becomes false, show "license expired" dialog
}
std::cout << "License expired. Shutting down." << std::endl;
return 0;
}
| Platform | HWID sources | Notes |
|---|
| Windows | GetAdaptersAddresses, WMI, GetVolumeInformation | Works out of the box with Windows SDK |
| Linux | /sys/class/net/*/address, /proc/cpuinfo, lsblk | Standard filesystem access |
| macOS | getifaddrs, sysctl, diskutil | May require Full Disk Access for disk serial |
GitHub
Full source, changelog, and issues: AuthForgeCC/authforge-cpp