Skip to content

Latest commit

 

History

16 Commits

Folders and files

Repository files navigation

AuthlyX C++ SDK

Official C++ SDK and console example for AuthlyX V3 (3.0.0 beta).

Full documentation: https://docs.authlyx.dev

Requirements

  • Windows, 64-bit
  • A C++20 compiler (Visual Studio 2022 or newer)
  • OpenSSL 3, libcurl and nlohmann/json

The easiest way to get the libraries is vcpkg. The vcpkg.json in this repo lists them, so vcpkg installs them for you during the build.

Build the example

git clone https://github.com/authlyx/AuthlyX-CPP-Example.git
cd AuthlyX-CPP-Example
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
cmake --build build --config Release

Before you build, open AuthlyX-CPP-Example/main.cpp and put your app key and version where the app is created:

AuthlyX app("YOUR_APP_KEY", "1.0.0");

You can find the app key under your app's credentials in the dashboard.

Add it to your own project

Copy AuthlyX.h into your project and include it:

#include "AuthlyX.h"
#include <iostream>

int main()
{
    AuthlyX app("YOUR_APP_KEY", "1.0.0");

    auto connected = app.initialize().get();
    if (!connected.ok())
    {
        std::cout << connected.message << '\n';
        return 1;
    }

    auto signedIn = app.login("YOUR_LICENSE_KEY").get();
    std::cout << signedIn.message << '\n';
}

Link OpenSSL, libcurl, nlohmann/json, crypt32 and advapi32. If you use CMake, the CMakeLists.txt here shows how.

Every call returns a std::future. Calling .get() waits for the reply, so in a GUI app do that on a worker thread and not on the UI thread. Most methods also take a callback if you prefer that style.

Signing in

app.login("YOUR_USERNAME", "YOUR_PASSWORD").get();
app.login("YOUR_LICENSE_KEY").get();
app.deviceLogin().get();

Device login signs in the current Windows user without a form. The device has to be approved in your app first. See Device login.

After signing in, app.userData() holds the account details:

auto user = app.userData();
auto username = user.value("Username", "");
auto plan = user.value("Plan", "");
auto expiry = user.value("ExpiryDate", "");

Methods

Area Methods
Connect initialize
Sign in login, licenseLogin, deviceLogin, registerUser, logout
Account userData, changePassword, redeemLicense, checkSession
Features getFeatures, getFeature, checkFeature
Metadata getAllMetadata, getMetadata, checkMetadata, setMetadata
Cloud variables getVariable, updateVariable
Scripts getScript
Logs and webhooks log, sendWebhook
Offline access saveOfflineAccess, hasOfflineAccess, hasAccess

Each method has its own page with examples under SDK methods.

Offline access

Once someone is signed in, saveOfflineAccess() stores a signed permit on that PC. If they open your app later without internet, they sign in with the same username and password or license key, and the SDK checks it against the saved permit. Each permit belongs to one app and one account, and signing out removes it. More in Offline access.

Errors

A failed call gives you a code and a message you can show to the user. Network problems and some setup errors throw authlyx::error instead, so wrap initialize() in a try block like the example does. All codes are listed in Errors.

Coming from 2.4

V3 is a new SDK, not a drop-in update. Apps use an app key instead of the old owner ID and secret, and the method names changed. Read Move from V2 to V3 before you switch.

License

MIT. See LICENSE.txt.