C# SDK

C# SDK for .NET applications, Unity projects, and WPF/WinForms apps. Uses HttpClient for modern async HTTP.

✓ Single file, no NuGet packages required

Drop Authon.cs into your project. Compatible with .NET Framework 4.6.1+ and .NET 6+.

Installation

Add Authon.cs to your project. No external packages needed — uses built-in System.Net.Http.

Project structure
text
MyApp/
├── Program.cs
├── Authon.cs       ← SDK class
└── MyApp.csproj

SDK Implementation

The full SDK class that wraps all Authon API calls:

Authon.cs
C#
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Management;

namespace AuthonSDK
{
    public class UserData
    {
        public string Username { get; set; } = "";
        public int Level { get; set; }
        public string ExpiresAt { get; set; } = "";
        public string SessionToken { get; set; } = "";
    }

    public class AppData
    {
        public string Name { get; set; } = "";
        public string Version { get; set; } = "";
    }

    public class Authon
    {
        private readonly string _appId;
        private readonly string _apiKey;
        private readonly string _apiUrl;
        private readonly HttpClient _http;

        public UserData User { get; private set; } = new();
        public AppData App { get; private set; } = new();
        public bool IsInitialized { get; private set; }
        public string LastError { get; private set; } = "";

        public Authon(string appId, string apiKey,
            string apiUrl = "https://api.authon.pro")
        {
            _appId = appId;
            _apiKey = apiKey;
            _apiUrl = apiUrl;
            _http = new HttpClient();
        }

        public async Task<bool> Init()
        {
            var res = await Post(new {
                type = "init", appId = _appId, apiKey = _apiKey
            });
            if (!res.Success) return false;

            App.Name = GetStr(res.Raw, "name");
            App.Version = GetStr(res.Raw, "version");
            IsInitialized = true;
            return true;
        }

        public async Task<bool> Login(string username,
            string password, string hwid = "")
        {
            var body = new {
                type = "login", appId = _appId, apiKey = _apiKey,
                username, password, hwid
            };
            var res = await Post(body);
            if (!res.Success) return false;

            User.Username = GetStr(res.Raw, "username");
            User.SessionToken = GetStr(res.Raw, "sessionToken");
            User.ExpiresAt = GetStr(res.Raw, "expiresAt");
            User.Level = GetInt(res.Raw, "level");
            return true;
        }

        public async Task<bool> Register(string username,
            string password, string licenseKey, string hwid = "")
        {
            var body = new {
                type = "register", appId = _appId, apiKey = _apiKey,
                username, password, licenseKey, hwid
            };
            var res = await Post(body);
            if (!res.Success) return false;

            User.Username = username;
            User.ExpiresAt = GetStr(res.Raw, "expiresAt");
            User.Level = GetInt(res.Raw, "level");
            return true;
        }

        public async Task<bool> License(string licenseKey,
            string hwid = "")
        {
            var body = new {
                type = "license", appId = _appId, apiKey = _apiKey,
                licenseKey, hwid
            };
            var res = await Post(body);
            if (!res.Success) return false;

            User.ExpiresAt = GetStr(res.Raw, "expiresAt");
            User.Level = GetInt(res.Raw, "level");
            return true;
        }

        public async Task<bool> Check()
        {
            var body = new {
                type = "check", appId = _appId, apiKey = _apiKey,
                sessionToken = User.SessionToken
            };
            return (await Post(body)).Success;
        }

        public async Task<string> GetVar(string key)
        {
            var body = new {
                type = "var", appId = _appId, apiKey = _apiKey,
                sessionToken = User.SessionToken, key
            };
            var res = await Post(body);
            return res.Success ? GetStr(res.Raw, "value") : "";
        }

        public async Task<bool> SetVar(string key, string value)
        {
            var body = new {
                type = "setvar", appId = _appId, apiKey = _apiKey,
                sessionToken = User.SessionToken, key, value
            };
            return (await Post(body)).Success;
        }

        public async Task<bool> Log(string message)
        {
            var body = new {
                type = "log", appId = _appId, apiKey = _apiKey,
                sessionToken = User.SessionToken, message
            };
            return (await Post(body)).Success;
        }

        // HWID helper using WMI
        public static string GetHWID()
        {
            try {
                var searcher = new ManagementObjectSearcher(
                    "SELECT SerialNumber FROM Win32_BaseBoard");
                foreach (var obj in searcher.Get())
                    return "HWID-" + obj["SerialNumber"]?.ToString();
            } catch { }
            return "HWID-UNKNOWN";
        }

        // Internal HTTP helper
        private async Task<ApiResponse> Post(object body)
        {
            try {
                var json = JsonSerializer.Serialize(body);
                var content = new StringContent(json,
                    Encoding.UTF8, "application/json");
                var res = await _http.PostAsync(_apiUrl + "/v1", content);
                var raw = await res.Content.ReadAsStringAsync();

                bool success = raw.Contains("\"success\":true");
                if (!success)
                    LastError = GetStr(raw, "message");
                return new ApiResponse { Success = success, Raw = raw };
            }
            catch (Exception ex) {
                LastError = ex.Message;
                return new ApiResponse { Success = false, Raw = "" };
            }
        }

        private string GetStr(string json, string key)
        {
            var search = $"\"{key}\":\"";
            int pos = json.IndexOf(search);
            if (pos == -1) return "";
            pos += search.Length;
            int end = json.IndexOf("\"", pos);
            return end == -1 ? "" : json[pos..end];
        }

        private int GetInt(string json, string key)
        {
            var search = $"\"{key}\":";
            int pos = json.IndexOf(search);
            if (pos == -1) return 0;
            pos += search.Length;
            int end = json.IndexOfAny(new[] { ',', '}' }, pos);
            return int.TryParse(json[pos..end], out int val)
                ? val : 0;
        }

        private struct ApiResponse {
            public bool Success;
            public string Raw;
        }
    }
}

Quick Start

Program.cs - Console Application
C#
using AuthonSDK;

const string APP_ID = "your-app-id";
const string API_KEY = "your-api-key";

var auth = new Authon(APP_ID, API_KEY);

// Initialize
Console.WriteLine("[*] Connecting...");
if (!await auth.Init())
{
    Console.WriteLine("[!] Failed: " + auth.LastError);
    return;
}
Console.WriteLine($"[+] Connected to {auth.App.Name} v{auth.App.Version}");

// Get HWID
string hwid = Authon.GetHWID();
Console.WriteLine($"[*] HWID: {hwid}");

// Login
Console.Write("Username: ");
string username = Console.ReadLine()!;
Console.Write("Password: ");
string password = Console.ReadLine()!;

if (!await auth.Login(username, password, hwid))
{
    Console.WriteLine("[!] Login failed: " + auth.LastError);
    return;
}

Console.WriteLine($"[+] Welcome {auth.User.Username}!");
Console.WriteLine($"    Level: {auth.User.Level}");
Console.WriteLine($"    Expires: {auth.User.ExpiresAt}");

// Verify session
if (await auth.Check())
    Console.WriteLine("[+] Session verified.");

// Log activity
await auth.Log("User logged in from C# app");

Console.WriteLine("\nApplication ready!");
Console.ReadKey();

WPF/WinForms Example

For GUI applications, call SDK methods from async event handlers:

LoginWindow.xaml.cs
C#
private Authon _auth = new("app-id", "api-key");

private async void Window_Loaded(object sender, RoutedEventArgs e)
{
    if (!await _auth.Init())
    {
        MessageBox.Show("Connection failed: " + _auth.LastError);
        Close();
    }
}

private async void BtnLogin_Click(object sender, RoutedEventArgs e)
{
    string hwid = Authon.GetHWID();
    bool success = await _auth.Login(
        txtUsername.Text, txtPassword.Password, hwid);

    if (success)
    {
        var main = new MainWindow(_auth);
        main.Show();
        Close();
    }
    else
    {
        lblError.Content = _auth.LastError;
    }
}

License-Only Authentication

License key validation
C#
var auth = new Authon(APP_ID, API_KEY);
await auth.Init();

Console.Write("Enter license key: ");
string key = Console.ReadLine()!;
string hwid = Authon.GetHWID();

if (await auth.License(key, hwid))
{
    Console.WriteLine($"[+] License valid! Level: {auth.User.Level}");
    Console.WriteLine($"    Expires: {auth.User.ExpiresAt}");
    // Continue to main app...
}
else
{
    Console.WriteLine("[!] Invalid: " + auth.LastError);
}

Server Variables

Working with variables
C#
// Get app-level variable (set by admin in dashboard)
string downloadUrl = await auth.GetVar("download_url");
string latestVersion = await auth.GetVar("app_version");

// Set user-level variable (per-user storage)
await auth.SetVar("theme", "dark");
await auth.SetVar("last_used", DateTime.Now.ToString());

// Retrieve user variable later
string theme = await auth.GetVar("theme"); // won't work - use getvar type
// Use the REST API directly for user vars if needed

Error Handling

Always check return values and use LastError for the error message:

Error handling pattern
C#
if (!await auth.Login(username, password, hwid))
{
    switch (auth.LastError)
    {
        case "Invalid credentials":
            ShowError("Wrong username or password");
            break;
        case "Hardware ID mismatch":
            ShowError("This account is locked to another device");
            break;
        case "Account banned":
            ShowError("Your account has been suspended");
            break;
        case "Subscription expired":
            ShowError("Your subscription has expired");
            break;
        default:
            ShowError(auth.LastError);
            break;
    }
}

Notes

.NET Version Compatibility

Works with .NET Framework 4.6.1+, .NET Core 3.1+, and .NET 5/6/7/8. For Unity, use .NET Standard 2.1 target.

HWID Generation

The built-in GetHWID() uses WMI (Win32_BaseBoard serial). For stronger binding, combine with CPU ID and disk serial.

Thread Safety

HttpClient is thread-safe. The SDK instance can be shared across threads, but avoid calling methods concurrently on the same instance.

Obfuscation

For production builds, consider using an obfuscator (ConfuserEx, .NET Reactor) to protect your credentials and SDK calls.