C++ guide
This page walks through the whole C++ SDK in the order you would use it in an app. Each step starts with the shortest code that works, then shows the other ways to do the same thing and when you would pick them. If you only want to get signed in quickly, read the first four sections and come back to the rest later.
Download the C++ SDK if you have not done so yet.
Requirements
You do not have to change any project setting. The header links the Windows libraries it needs (WinHTTP, CNG, DPAPI, user32, shell32, advapi32 and crypt32) by itself under Visual Studio and clang-cl. With MinGW, add -lwinhttp -lbcrypt -lcrypt32 -ladvapi32 -luser32 -lshell32 to your link command.
Add the SDK to your project
Copy AuthlyX.h next to your source files and include it:
That is all for most projects. If you include AuthlyX.h from many .cpp files and want faster builds, compile the SDK code once instead of in every file:
- Add
AUTHLYX_SEPARATE_IMPLEMENTATIONto Project > Properties > C/C++ > Preprocessor > Preprocessor Definitions for all configurations. - In exactly one
.cppfile, defineAUTHLYX_IMPLEMENTATIONbefore the include:
Every other file keeps a plain #include "AuthlyX.h".
If your project already has nlohmann/json on its include path, the SDK finds it and uses your copy instead of the one inside the header. To always use the copy inside the header, define AUTHLYX_EMBEDDED_JSON.
Create the client
The first value is your app’s AppKey. Find it in the dashboard under your application’s credentials. The second value is the version of the program you are building. AuthlyX compares it with the versions you allow in the dashboard, so raise it each time you ship a new build. See Allowed Versions.
Some things to know about the client:
- Create one client for the whole program and keep it alive until the program exits. A global variable, like above, is the simplest way. A member of your main window or app class works too.
- The client cannot be copied. Pass it around by reference (
AuthlyX&) or keep a pointer to it. AuthlyX,authlyx::AuthlyXandauthlyx::clientare the same class. Use whichever name you like.- Creating the client does not connect yet. It only prepares the SDK. Nothing is sent until you call
init().
If you want to change how the SDK behaves, start from the default options instead:
All the options are listed in Options near the end of this page.
Every call returns a future
This is the one thing that trips most people up, so it gets its own section.
Calls that talk to AuthlyX, such as init, login or getVariable, return a std::future<authlyx::result>, not the result itself. A future is a value that will be ready later. Calling .get() on it waits until the reply has arrived and then hands you the result:
You will normally write both on one line:
If you forget .get(), result is still the future, and the compiler stops at the next line with an error such as E0135 class "std::future<authlyx::result>" has no member "ok". Add .get() and it goes away.
There are three ways to deal with a future, and you can mix them in one program:
“Waits” means the line does not finish until AuthlyX replies, usually well under a second. That is fine in a console app or on a worker thread. On the thread that draws your window (the UI thread or render loop) it freezes the window for that time, so use a callback or a worker thread there. Threads and GUI apps shows how.
Start the SDK
Call init() once, before signing in. It checks your AppKey and version, sets up this installation and reads update information. initialize() is the same call with a longer name.
Simplest
This waits until AuthlyX replies and ignores the result. If your app needs an update, the SDK still shows the update message box. If there is no internet, your app carries on and the sign-in that follows will report the problem. This is the shortest way to start and is fine for a lot of apps.
Check the result
init() gives you a result even when something is wrong, instead of throwing, so you do not need try here. These are the codes you can get:
With a callback
This returns straight away. The SDK runs the lambda on a background thread once the reply arrives. The parameter is the result; you can name it anything. With C++14 or newer you can write [](auto started) instead of naming the type. Plain C++11 compilers need authlyx::result.
A callback never throws. If something goes wrong, the result it receives has ok() set to false with a code and message.
Sign in
There are three ways to sign in. Use the ones you enabled in the dashboard. See Choose a sign-in method.
app.licenseLogin("YOUR_LICENSE_KEY") does the same as app.login with one value. Device login only works for devices you approved first; see Device login.
Simplest
app.login(license); waits for the reply. hasAccess() then tells you whether the user is signed in. You do not get the reason when it fails, which is the price for the short code.
Show why it failed
When AuthlyX refuses a sign-in, .get() throws authlyx::error. Catch it and show its message:
If .get() returns, the sign-in worked. e.what() is a message you can show to the user as it is. e.code is a fixed code for your own checks, such as INVALID_CREDENTIALS, LICENSE_NOT_FOUND, LICENSE_EXPIRED, LICENSE_BANNED, DEVICE_NOT_ALLOWED or DEVICE_LIMIT_REACHED. e.kind says what sort of problem it was:
All codes are on the Errors page.
With a callback
No try is needed. A refused sign-in arrives as a result with ok() false and the same code and message the error would have had.
A sign-in function you can reuse
Most apps wrap sign-in in a function that returns true or false and fills in an error message:
Create an account
registerUser creates a user account with a username, password and a license key, and signs it in:
Change the password or add time
Both need a signed-in user:
redeemLicense adds the time and plan of another key to the signed-in account. Both throw authlyx::error when they fail, like login.
Read the account
After sign-in, app.userData() returns the account details. Store it in a variable once, then read the fields from that variable:
The names match the C# SDK:
DaysLeft is counted from AuthlyX’s clock, not the PC’s, so changing the Windows date does not change it. One hour left shows as 1.
Why auto u = app.userData();
userData() is a function that returns a copy of the account at the moment you call it. Taking that copy into a variable means:
- You write
u.Planinstead ofapp.userData().Planevery time. - All the fields you read come from the same moment.
- The copy is yours. The SDK can update its own data in the background (it does on every heartbeat) without changing values halfway through your function, so it is safe on any thread.
A local variable only exists inside the function where you declare it, so each function that reads account details starts with its own auto u = app.userData();. It is cheap, even if you call it every frame.
You can still skip the variable when you only need one value:
Before sign-in, and after sign-out, the copy is empty: u.empty() is true and the text fields are "".
Functions that return text, numbers and yes/no
Small helper functions keep your UI code tidy. Here are some you can copy.
Text:
Numbers:
Yes or no:
Features and metadata
Features come from the plan and the account. Some are on/off, some carry a value such as "high" or 90. Metadata is extra information you attach to accounts, such as a Discord name or a level. See Features and metadata for how to set them up.
Read them from the account
The quickest way is from userData(). It does not contact AuthlyX, so you can use it anywhere, even every frame:
Pass a second value to choose your own fallback:
None of these throw. Text such as "45" or "true" is converted when it can be, and yes, on and 1 count as true. The values refresh on every heartbeat, so a change you make in the dashboard shows up in the next userData() call without signing in again.
A feature function you can drop into a menu:
Ask AuthlyX directly
These calls go to AuthlyX and return the current value from the server. Use them when you need to be sure the value is up to the second:
result.data is an authlyx::json object (nlohmann/json). data["value"] gives you the raw JSON value, and data.value("value", fallback) gives it to you as the type of the fallback, or the fallback if it is missing. If the stored value has a different type, for example a number where you passed "", data.value throws nlohmann::json::type_error, so prefer the userData() helpers above when you just want a value. Like login, these calls throw authlyx::error when the request fails.
Save metadata
Only keys you allowed for SDK writes in the dashboard can be changed this way.
Cloud variables
Cloud variables are values you store in the dashboard and read from your app, such as a download link or a message of the day. See Cloud variables.
To change a variable that you allowed the app to write:
A small helper that never throws:
Scripts
Scripts are signed text you store in the dashboard. The SDK checks the signature before giving it to you. It does not run the script; what you do with the text is up to you. See Scripts.
To get a specific revision instead of the newest:
With a callback:
Logs and webhooks
Send a line to your app’s logs in the dashboard:
Send an event to your own server through a webhook you set up in the dashboard. The second value is any JSON:
If you do not need to wait for these, drop the .get(). The call still waits for its reply when the line ends, but you do not handle the result. To send without waiting at all, run it in a thread; see Threads and GUI apps.
Staying signed in
After sign-in the SDK keeps the session alive by itself. It checks in with AuthlyX in the background (a heartbeat), by default about every 10 minutes, and refreshes features and metadata each time. If you ban, pause or expire the account in the dashboard, the next heartbeat ends the session.
Check access
hasAccess() returns true while the user is signed in. It does not contact AuthlyX, so it is cheap enough for every frame:
Get told when access ends
Set on_invalidated to run code when AuthlyX ends the session, for example after a ban:
on_connection receives online, disconnected or untrusted when the connection state changes. Both run on a background thread, so if you touch your UI from them, hand the work to your UI thread.
Check now
checkSession() checks in right away. onResume() is the same call, meant for when your app comes back from sleep or a long pause:
To run the heartbeat yourself instead of letting the SDK do it, set options.heartbeat = "manual"; and call checkSession() from your own timer. Most apps should leave it automatic. More in Sessions and heartbeats.
Offline access
Offline access lets someone keep using your app for a while without internet, for example on a plane. You turn it on and set how long it lasts in the dashboard. See Offline access.
Save it after a successful online sign-in:
Later, without internet, init() returns OFFLINE_MODE (with ok() true), and the user signs in with the same license key or username and password. The SDK checks them against the saved permit and login returns the code OFFLINE_ACCESS. userData() works as normal; online-only calls such as getVariable fail until the connection comes back.
app.hasOfflineAccess() tells you whether this PC has a valid saved permit. Signing out deletes it.
Updates
When this version is not allowed, init() fails with UPDATE_REQUIRED or VERSION_MISMATCH, and the SDK shows a message box with the new version, its release notes and a button to open your download page. When a newer version exists but this one is still allowed, the SDK shows an Update available box once after sign-in.
To show your own window instead, turn the box off and read the update details from the result:
The update details are version, url and notes. Any of them can be missing, which is why the helper checks before reading.
Set versions and download links under your app’s Updates settings. See Automatic updates.
Sign out
This ends the session on AuthlyX, clears userData() and deletes saved offline access on this PC. If there is no internet it still signs out locally and then throws a network error, so wrap it in try if you call .get().
When your program exits, the client shuts down by itself. To stop it earlier, call app.close(). After close() the client cannot be used again.
Threads and GUI apps
Every network call waits when you call .get(), and it also waits at the end of the line if you just call it. In a console app that is what you want. In a window, the wait has to happen somewhere other than the thread that draws the window.
Use callbacks
The simplest option. The call returns at once and your code runs when the reply arrives:
The callback runs on a background thread, so share data with your UI through an atomic or a mutex like above, and let your render loop pick it up.
Use your own thread
For calls that have no callback version, or when you want to run several steps in a row, start a thread:
Callbacks exist for init, initialize, login (both forms), getVariable and getScript. Every other call works the same way inside a thread.
What is safe from any thread
userData(),hasAccess()andhasOfflineAccess(): safe on any thread at any time, including every frame of an ImGui loop.- Network calls: safe to start from any thread. The SDK sends them one at a time, so starting several at once is fine; they just queue.
An ImGui menu, for example, can read everything it shows directly:
Cancel a call
Pass a stop token as the last value of any network call. When you request a stop, that call fails with a cancelled error:
On C++20 these are the standard std::stop_source and std::stop_token.
Results and errors
Every call returns, or passes to your callback, an authlyx::result:
When .get() throws, you get an authlyx::error. It is a std::runtime_error, so catch (const std::exception&) also catches it:
Options
Start from authlyx::defaultOptions(appKey, version) and change what you need:
Common problems
has no member "ok" or has no member "message". You are holding the future. Add .get(): auto r = app.login(key).get();.
'auto' not allowed in lambda parameter. Your compiler is in C++11 mode. Write [](authlyx::result r) instead of [](auto r).
The window freezes when signing in. A .get() or a plain call is running on the UI thread. Use a callback or a thread.
class "AuthlyX" has no member "response" or no member Login. That is V2 code. V3 uses login, init and returned results. See Move from V2 to V3.
Sign-in fails with DEVICE_NOT_ALLOWED. The account is locked to another PC or Windows user. Reset its device in the dashboard.
The program builds slowly. Use AUTHLYX_SEPARATE_IMPLEMENTATION as shown in Add the SDK to your project.
A complete program
Each method also has its own page with every language side by side under SDK methods.

