C# guide
This page walks through the whole C# SDK in the order you would use it. Each step starts with the shortest code that works, then shows the other ways to write it. The examples work the same in a console app, WinForms and WPF; where they differ, the page says so.
Download the C# SDK or install it from NuGet if you have not done so yet.
Requirements
Add the SDK to your project
The easiest way is NuGet:
In Visual Studio you can also right-click the project, choose Manage NuGet Packages, tick Include prerelease and install AuthlyX.
To use the source file instead, add AuthlyX.cs to your project and install BouncyCastle.Cryptography (or BouncyCastle 1.8.9 or newer) and Newtonsoft.Json. On .NET Framework, also add a reference to System.Net.Http.
Then add the namespace at the top of each file that uses the SDK:
Create the client
The first value is your app’s AppKey. Find it in the dashboard under your application’s credentials. The second 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.
Create one client for the whole program. A public static field in Program is the simplest place, because every form and class can then reach it as Program.app:
Creating the client does not connect yet. Nothing is sent until you call init.
The constructor takes a few optional settings by name:
All of them are listed in Options near the end of this page.
Three ways to call the SDK
Calls that talk to AuthlyX, such as init, login or getVariable, can be used in three ways. You can mix them in one program.
The callback style never throws. If something goes wrong, the result it receives has ok set to false with a code and message. With await or waiting, a refused call throws AuthlyXException instead, so wrap it in try.
Do not wait with GetResult(), .Result or .Wait() on a UI thread. The window freezes until AuthlyX replies.
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 method with a longer name.
With a callback
This returns straight away. In WinForms and WPF the callback runs on the UI thread, which is why it can touch loginButton directly. The parameter is the result; you can name it anything.
With await
async Task Main needs C# 7.1 or newer, which every supported project has.
init gives you a result even when something is wrong, instead of throwing. These are the codes you can get:
Sign in
One value is a license key, two values are a username and password, and deviceLogin signs in the current Windows user with no form. Device login only works for devices you approved first; see Device login. Use the methods you enabled in the dashboard; see Choose a sign-in method.
With a callback
result.message is ready to show to the user. result.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. All codes are on the Errors page.
With await
If await returns, the sign-in worked. error.Kind says what sort of problem it was:
A sign-in method you can reuse
Create an account, change the password, add time
registerUser creates a user account and signs it in. changePassword and redeemLicense need a signed-in user. Each one also has an await form, for example await app.redeemLicense("ANOTHER_LICENSE_KEY");.
Read the account
After sign-in, app.userData holds the account details:
app.user is the same object as app.userData. Before sign-in, after sign-out, and when access ends, the text properties are empty and ExpiryDate is null.
You can read userData from any thread. Features and metadata in it refresh on every heartbeat, so read them again when you need the latest values instead of keeping them in a field for hours.
Methods that return text, numbers and yes/no
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 attached to accounts, such as a Discord name or a level. See Features and metadata.
Read them from the account
These do not contact AuthlyX, so they are safe to call often:
hasFeature is true when that on/off feature is enabled and the user has access. The values refresh on every heartbeat, so dashboard changes show up without signing in again.
Small helpers for text, numbers and yes/no values:
Use the same pattern with app.userData.Metadata for metadata. These helpers need using System.Globalization;.
Ask AuthlyX directly
These calls get the current value from the server:
data is a JObject (Newtonsoft.Json). getFeatures returns data["features"], getAllMetadata returns data["metadata"], getFeature and getMetadata(key) return data["value"], and the two check calls return data["enabled"]. Each also has a callback form, such as app.getFeature("quality", result => { ... });.
Save metadata
Only keys you allowed for SDK writes in the dashboard can be changed.
Cloud variables
Cloud variables are values you store in the dashboard, such as a download link or a message of the day. See Cloud variables.
For variables, data is the value itself as a string. To change one that you allowed the app to write:
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. See Scripts.
With a callback:
Logs and webhooks
log writes a line to your app’s logs in the dashboard. sendWebhook sends an event to a webhook you set up in the dashboard; the second value is any JSON. Both also take a callback, for example app.log("Opened settings", result => { });, if you do not want to await them. JObject needs using Newtonsoft.Json.Linq;.
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
app.HasAccess is true while the user is signed in. It does not contact AuthlyX:
Get told when access ends
SessionInvalidated fires when AuthlyX ends the session, for example after a ban. ConnectionChanged fires with Online, Disconnected, Untrusted or Disposed, and app.Connection holds the current state. Both events run on a background thread, so use BeginInvoke in WinForms or Dispatcher.BeginInvoke in WPF before touching controls.
Check now
onResume() does the same and is meant for when your app wakes from sleep. To run the heartbeat yourself, create the client with 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. 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 the sign-in succeeds with the code OFFLINE_ACCESS. userData works as normal; online-only calls such as getVariable fail until the connection returns.
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, 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, turn the box off and read the details yourself:
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. Without internet it still signs out locally; the await form then throws a Network error, and the callback form reports it in the result.
When your program exits you do not need to do anything else. To shut the client down earlier, call app.Dispose(). A disposed client cannot be used again.
Threads and UI apps
- Callbacks capture the thread they were started from. Start them from a form or window and they come back on the UI thread, so you can set
label.Textdirectly. Started from a console app or a background thread, they run on a thread-pool thread. awaitin anasync voidbutton handler also comes back to the UI thread.- Events (
SessionInvalidated,ConnectionChanged) run on a background thread. UseBeginInvokebefore touching controls. userData,HasAccessandHasOfflineAccesscan be read from any thread at any time.- Network calls can be started from any thread. The SDK sends them one at a time, so starting several at once is fine; they queue.
Cancel a call
Every await form takes a CancellationToken as its last value:
A cancelled call throws OperationCanceledException or an AuthlyXException with Kind set to Cancelled.
Results and errors
Every call returns, or passes to your callback, a Result<T>:
AuthlyXException has Message, Code, Kind, Status, RequestId and Data.
Options
Pass these by name to the constructor:
For full control, build a ClientOptions from AuthlyX.defaultOptions(appKey, version) and pass it to new AuthlyX(options). It also has BuildHash for Application hashes and Storage to keep the SDK’s protected files in another folder with new WindowsProtectedStore(path).
Common problems
'AuthlyX' does not contain a definition for 'response' or for Login. That is V2 code. See Move from V2 to V3.
The window freezes when signing in. Something is waiting with .Result, .Wait() or GetResult() on the UI thread. Use a callback or await.
Cross-thread operation not valid. A SessionInvalidated or ConnectionChanged handler touched a control. Wrap the code in BeginInvoke.
Sign-in fails with DEVICE_NOT_ALLOWED. The account is locked to another PC or Windows user. Reset its device in the dashboard.
A complete console program
Each method also has its own page with every language side by side under SDK methods.

