Java guide
This page walks through the whole Java 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. Every example compiles on Java 8, so it does not use var.
Download the Java SDK if you have not done so yet.
Requirements
On Linux and macOS, set your own systemId and storage in the options.
Add the SDK to your project
Put AuthlyX.java in src/main/java/app/authlyx/; its package is app.authlyx. Then add the two libraries. With Maven:
With Gradle:
Import the client where you use it:
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 and keep it in a static final field or pass it to the classes that need it. Creating it does not connect; nothing is sent until you call init. The client is AutoCloseable, so a console program can also use try-with-resources:
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 return a CompletableFuture. You can use it in three ways:
“Waits” means the line does not finish until AuthlyX replies. That is fine in a console program or a worker thread, but not on the Swing or JavaFX UI thread, where the window would freeze.
Callbacks exist for init, initialize, licenseLogin, login with a username and password, getVariable and getScriptWithCallback. Callbacks and thenAccept run on the SDK’s background thread, so use SwingUtilities.invokeLater or Platform.runLater before touching UI.
When join() fails it throws a CompletionException with the real AuthlyX.SdkException inside. This small helper unwraps it:
Start the SDK
Call init once, before signing in. initialize is the same method with a longer name.
init gives you a result even when something is wrong, instead of failing:
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. licenseLogin("YOUR_LICENSE_KEY") is the same as login with one value. Device login only works for devices you approved first; see Device login.
When AuthlyX refuses a sign-in, join() throws:
getMessage() is text you can show to the user. 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, no try is needed. For a license key the callback form is licenseLogin:
A sign-in method you can reuse:
It returns an empty string when the sign-in worked and the reason when it did not.
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. All three throw the same way as login.
Read the account
After sign-in, app.userData holds the account details as a Jackson JsonNode. Read each field with path(...), which never returns null:
Before sign-in and after sign-out, app.userData is an empty object, so every path(...) returns its fallback. Store app.userData in a local variable at the start of a method so every field you read comes from the same moment.
Methods that return text, numbers and yes/no
daysLeft() 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, copy the helpers with "metadata" in place of "featureValues".
Ask AuthlyX directly
getMetadata() with no key returns all metadata, like getAllMetadata().
Save metadata
Only keys you allowed for SDK writes in the dashboard can be changed.
Cloud variables
See Cloud variables.
Scripts
The second value of getScript is a revision number, or null for the newest. 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 can be a Map, a Jackson node or any object Jackson can turn into JSON.
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, set the callbacks in the options:
onConnection receives online, disconnected or untrusted. Both run on a background thread. To check right away, call app.checkSession().join(); app.onResume() does the same and is meant for when your app wakes from sleep. To run the heartbeat yourself, set options.heartbeat = "manual"; and call checkSession() from your own timer. 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().join() 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.updatePrompt = false; and read the details:
See Automatic updates.
Sign out and shut down
logout ends the session, clears userData and deletes saved offline access on this PC. close stops the background threads. A closed client cannot be used again.
Swing and JavaFX
Never call join() on the UI thread. Use a callback or thenAccept, and move back to the UI thread before touching components:
In JavaFX, use Platform.runLater in the same place. Reading app.userData is safe from any thread.
Results and errors
AuthlyX.Result has ok() / success(), failed(), code(), message(), requestId() and data(), a Jackson JsonNode. decode(MyType.class) turns data() into your own class.
AuthlyX.SdkException is a RuntimeException with getMessage(), code, kind, status, requestId and data.
Options
Start from AuthlyX.defaults(appKey, version) and change what you need:
A complete program
Each method also has its own page with every language side by side under SDK methods.

