Rust guide
This page walks through the whole Rust 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.
Download the Rust SDK if you have not done so yet.
Requirements
On Linux and macOS, AuthlyX::new returns an error because there is no Windows user ID to read. Use AuthlyX::withOptions with your own systemId and storage, as shown in Options.
Add the SDK to your project
Unzip the download into a folder in your project, for example authlyx, and add it to Cargo.toml together with Tokio and serde_json:
chrono is only needed for the date helpers further down. With Rust older than 1.84, copy the Cargo.lock from the download into your project so Cargo picks dependency versions that work with your compiler.
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. It is cheap to clone, and every clone shares the same session, so pass clones to the tasks and functions that need it. Client is another name for the same type. Creating the client does not connect; nothing is sent until you call init.
To change settings, start from the defaults:
All the options are listed in Options.
Three ways to call the SDK
Calls that talk to AuthlyX are async and return Result<Response, Error>. You can use them in three ways:
.await
Callback
This starts the call on a Tokio task and returns a JoinHandle straight away. The callback receives the full Result on that task. Callback forms exist for initWith, initializeWith, licenseLoginWith, getVariableWith and getScriptWith. They must be called from inside a Tokio runtime.
Blocking
If the rest of your program is not async, make a runtime once and wait on each call:
Keep the runtime alive for as long as you use the client, because the heartbeat runs on it. Every .await example below works the same with runtime.block_on(...) around the call.
Start the SDK
Call init once, before signing in. initialize is the same method with a longer name.
For the usual problems init returns Ok with success false, so ? only stops on unusual failures such as a reply that failed verification:
Sign in
licenseLogin takes a license key, login takes 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.
When AuthlyX refuses a sign-in, the call returns Err(Error). Using ? passes it up; to show it instead, match on it:
error.message is text you can show to the user; printing the error with {} puts the code in front of it. error.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. error.kind says what sort of problem it was:
All codes are on the Errors page.
With a callback:
A sign-in function you can reuse:
Create an account, change the password, add time
registerUser creates a user account and signs it in. The other two need a signed-in user.
Read the account
After sign-in, userData() returns a copy of the account details as a serde_json::Value:
Indexing a missing key gives Value::Null instead of panicking, so unwrap_or covers fields that are not there.
Before sign-in and after sign-out it is an empty object. Because it is a copy, call userData() again when you want the latest values.
Functions that return text, numbers and yes/no
days_left rounds up, so one hour left counts as 1 day.
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. See Features and metadata.
Read them from the account
These do not contact AuthlyX:
The values refresh on every heartbeat, so dashboard changes show up without signing in again. For metadata helpers, copy the feature ones with "metadata" in place of "featureValues".
Ask AuthlyX directly
In Rust, getMetadata() returns all metadata and getMetadataValue(key) returns one key. To turn data into your own struct, derive Deserialize and call response.decode::<YourType>().
Save metadata
Only keys you allowed for SDK writes in the dashboard can be changed.
Cloud variables
See Cloud variables.
Scripts
The second value is a revision number, or None for the newest. getScriptWith(name, revision, callback) is the callback form. The SDK checks the script’s signature before returning it. It does not run the script. See Scripts.
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 value.
Staying signed in
After sign-in the SDK 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, the next heartbeat ends the session.
To be told when the session ends or the connection changes, subscribe to events:
Event::Connection carries online, disconnected or untrusted. To check right away, call app.checkSession().await; app.onResume().await does the same and is meant for when your app wakes from sleep. To run the heartbeat yourself, build the options with .withHeartbeat("manual")? and call checkSession from your own tokio::time::interval. More in Sessions and heartbeats.
Offline access
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. app.hasOfflineAccess().await tells you whether this PC has a valid saved permit. Signing out deletes it. See Offline access.
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. To show your own window, set options.update_prompt = false and read the details:
See Automatic updates.
Sign out and shut down
logout ends the session, clears the account details and deletes saved offline access on this PC. close stops the heartbeat. A closed client cannot be used again.
Tasks and threads
AuthlyX is Clone, Send and Sync. To use it in another task, clone it first:
Calls on one client run one at a time, so starting many at once is safe but they wait for each other. In a GUI built with egui, iced or similar, run SDK calls on a Tokio task and send the result back to the UI with a channel, rather than calling block_on inside the UI loop.
Results and errors
Response has success, code, message, request_id and data (a serde_json::Value), plus ok(), failed() and decode::<T>().
Error has code, message, kind, status, request_id and data. It implements std::error::Error, so ? works in functions that return Box<dyn std::error::Error>.
Options
Start from AuthlyX::defaults(app_key, version)? and change what you need:
Events are not options in Rust; use subscribe() as shown in Staying signed in.
A complete program
Each method also has its own page with every language side by side under SDK methods.

