Java SDK

Java integration using HttpClient (Java 11+). No external libraries required.

Standard library only

Uses java.net.http.HttpClient available since Java 11. No Maven/Gradle dependencies needed.

Installation

Add Authon.java to your project. Requires Java 11 or newer.

Project structure
text
src/
├── Main.java
└── Authon.java     ← SDK class
Compile and run
bash
javac Main.java Authon.java
java Main

SDK Implementation

Authon.java
Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Authon {
    private final String appId;
    private final String apiKey;
    private final String apiUrl;
    private final HttpClient client;

    private String sessionToken = "";
    private String lastError = "";
    private boolean initialized = false;

    // User data
    private String username = "";
    private int level = 0;
    private String expiresAt = "";

    // App data
    private String appName = "";
    private String appVersion = "";

    public Authon(String appId, String apiKey) {
        this(appId, apiKey, "https://api.authon.pro");
    }

    public Authon(String appId, String apiKey, String apiUrl) {
        this.appId = appId;
        this.apiKey = apiKey;
        this.apiUrl = apiUrl;
        this.client = HttpClient.newBuilder()
            .connectTimeout(Duration.ofSeconds(10))
            .build();
    }

    private String post(String jsonBody) {
        try {
            HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(apiUrl + "/v1"))
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(jsonBody))
                .timeout(Duration.ofSeconds(10))
                .build();

            HttpResponse<String> response = client.send(
                request, HttpResponse.BodyHandlers.ofString());
            return response.body();
        } catch (Exception e) {
            lastError = e.getMessage();
            return "{\"success\":false,\"message\":\"" + e.getMessage() + "\"}";
        }
    }

    private boolean isSuccess(String response) {
        if (response.contains("\"success\":true")) {
            return true;
        }
        lastError = extractField(response, "message");
        return false;
    }

    private String extractField(String json, String key) {
        Pattern p = Pattern.compile("\"" + key + "\":\"([^\"]*)\"");
        Matcher m = p.matcher(json);
        return m.find() ? m.group(1) : "";
    }

    private int extractInt(String json, String key) {
        Pattern p = Pattern.compile("\"" + key + "\":(\\d+)");
        Matcher m = p.matcher(json);
        return m.find() ? Integer.parseInt(m.group(1)) : 0;
    }

    public boolean init() {
        String body = String.format(
            "{\"type\":\"init\",\"appId\":\"%s\",\"apiKey\":\"%s\"}",
            appId, apiKey);
        String resp = post(body);
        if (isSuccess(resp)) {
            appName = extractField(resp, "name");
            appVersion = extractField(resp, "version");
            initialized = true;
            return true;
        }
        return false;
    }

    public boolean login(String username, String password, String hwid) {
        String body = String.format(
            "{\"type\":\"login\",\"appId\":\"%s\",\"apiKey\":\"%s\"," +
            "\"username\":\"%s\",\"password\":\"%s\",\"hwid\":\"%s\"}",
            appId, apiKey, username, password, hwid);
        String resp = post(body);
        if (isSuccess(resp)) {
            this.username = extractField(resp, "username");
            this.level = extractInt(resp, "level");
            this.expiresAt = extractField(resp, "expiresAt");
            this.sessionToken = extractField(resp, "sessionToken");
            return true;
        }
        return false;
    }

    public boolean register(String username, String password,
                           String licenseKey, String hwid) {
        String body = String.format(
            "{\"type\":\"register\",\"appId\":\"%s\",\"apiKey\":\"%s\"," +
            "\"username\":\"%s\",\"password\":\"%s\"," +
            "\"licenseKey\":\"%s\",\"hwid\":\"%s\"}",
            appId, apiKey, username, password, licenseKey, hwid);
        String resp = post(body);
        if (isSuccess(resp)) {
            this.username = username;
            this.level = extractInt(resp, "level");
            this.expiresAt = extractField(resp, "expiresAt");
            return true;
        }
        return false;
    }

    public boolean license(String licenseKey, String hwid) {
        String body = String.format(
            "{\"type\":\"license\",\"appId\":\"%s\",\"apiKey\":\"%s\"," +
            "\"licenseKey\":\"%s\",\"hwid\":\"%s\"}",
            appId, apiKey, licenseKey, hwid);
        String resp = post(body);
        if (isSuccess(resp)) {
            this.level = extractInt(resp, "level");
            this.expiresAt = extractField(resp, "expiresAt");
            this.sessionToken = extractField(resp, "sessionToken");
            return true;
        }
        return false;
    }

    public boolean check() {
        String body = String.format(
            "{\"type\":\"check\",\"appId\":\"%s\",\"apiKey\":\"%s\"," +
            "\"sessionToken\":\"%s\"}",
            appId, apiKey, sessionToken);
        return isSuccess(post(body));
    }

    public String getVar(String key) {
        String body = String.format(
            "{\"type\":\"var\",\"appId\":\"%s\",\"apiKey\":\"%s\"," +
            "\"sessionToken\":\"%s\",\"key\":\"%s\"}",
            appId, apiKey, sessionToken, key);
        String resp = post(body);
        return isSuccess(resp) ? extractField(resp, "value") : "";
    }

    public boolean setVar(String key, String value) {
        String body = String.format(
            "{\"type\":\"setvar\",\"appId\":\"%s\",\"apiKey\":\"%s\"," +
            "\"sessionToken\":\"%s\",\"key\":\"%s\",\"value\":\"%s\"}",
            appId, apiKey, sessionToken, key, value);
        return isSuccess(post(body));
    }

    public boolean log(String message) {
        String body = String.format(
            "{\"type\":\"log\",\"appId\":\"%s\",\"apiKey\":\"%s\"," +
            "\"sessionToken\":\"%s\",\"message\":\"%s\"}",
            appId, apiKey, sessionToken, message);
        return isSuccess(post(body));
    }

    public byte[] downloadFile(String fileId) {
        String body = String.format(
            "{\"type\":\"file\",\"appId\":\"%s\",\"apiKey\":\"%s\"," +
            "\"sessionToken\":\"%s\",\"fileId\":\"%s\"}",
            appId, apiKey, sessionToken, fileId);
        String resp = post(body);
        if (isSuccess(resp)) {
            String url = apiUrl + extractField(resp, "downloadUrl");
            try {
                HttpRequest req = HttpRequest.newBuilder()
                    .uri(URI.create(url)).GET().build();
                HttpResponse<byte[]> r = client.send(
                    req, HttpResponse.BodyHandlers.ofByteArray());
                return r.body();
            } catch (Exception e) {
                lastError = e.getMessage();
            }
        }
        return new byte[0];
    }

    public static String getHWID() {
        String info = System.getProperty("os.name")
            + System.getProperty("user.name")
            + Runtime.getRuntime().availableProcessors();
        return "HWID-" + Integer.toHexString(info.hashCode()).toUpperCase();
    }

    // Getters
    public String getUsername() { return username; }
    public int getLevel() { return level; }
    public String getExpiresAt() { return expiresAt; }
    public String getAppName() { return appName; }
    public String getAppVersion() { return appVersion; }
    public String getLastError() { return lastError; }
    public boolean isInitialized() { return initialized; }
}

Quick Start

Main.java
Java
import java.util.Scanner;

public class Main {
    static final String APP_ID = "your-app-id";
    static final String API_KEY = "your-api-key";

    public static void main(String[] args) {
        Authon auth = new Authon(APP_ID, API_KEY);
        Scanner scanner = new Scanner(System.in);

        // Initialize
        System.out.println("[*] Connecting...");
        if (!auth.init()) {
            System.out.println("[!] Failed: " + auth.getLastError());
            return;
        }
        System.out.printf("[+] Connected to %s v%s%n",
            auth.getAppName(), auth.getAppVersion());

        // Login
        String hwid = Authon.getHWID();
        System.out.print("Username: ");
        String username = scanner.nextLine();
        System.out.print("Password: ");
        String password = scanner.nextLine();

        if (!auth.login(username, password, hwid)) {
            System.out.println("[!] Login failed: " + auth.getLastError());
            return;
        }

        System.out.printf("[+] Welcome %s!%n", auth.getUsername());
        System.out.printf("    Level: %d%n", auth.getLevel());
        System.out.printf("    Expires: %s%n", auth.getExpiresAt());

        // Verify session
        if (auth.check()) {
            System.out.println("[+] Session verified.");
        }

        // Log activity
        auth.log("User logged in from Java app");
        System.out.println("\nApplication ready!");
    }
}

License-Only Authentication

License key validation
Java
Authon auth = new Authon(APP_ID, API_KEY);
auth.init();

String key = "AUTH-XXXX-XXXX-XXXX"; // from user input
String hwid = Authon.getHWID();

if (auth.license(key, hwid)) {
    System.out.printf("[+] License valid! Level: %d%n", auth.getLevel());
    System.out.printf("    Expires: %s%n", auth.getExpiresAt());
} else {
    System.out.println("[!] Invalid: " + auth.getLastError());
}

Server Variables

Working with variables
Java
// Get app-level variable
String downloadUrl = auth.getVar("download_url");
String latestVersion = auth.getVar("app_version");

// Set user-level variable
auth.setVar("theme", "dark");
auth.setVar("last_used", "2025-06-15");

System.out.println("Download URL: " + downloadUrl);
System.out.println("Latest version: " + latestVersion);

File Download

Download a protected file
Java
import java.io.FileOutputStream;

byte[] fileBytes = auth.downloadFile("your-file-id");
if (fileBytes.length > 0) {
    try (FileOutputStream fos = new FileOutputStream("downloaded_module.bin")) {
        fos.write(fileBytes);
    }
    System.out.printf("[+] File downloaded (%d bytes)%n", fileBytes.length);
} else {
    System.out.println("[!] Download failed: " + auth.getLastError());
}

Error Handling

Error handling pattern
Java
if (!auth.login(username, password, hwid)) {
    String error = auth.getLastError();

    if (error.contains("Invalid credentials")) {
        System.out.println("Wrong username or password");
    } else if (error.contains("Hardware ID mismatch")) {
        System.out.println("This account is locked to another device");
    } else if (error.contains("Account banned")) {
        System.out.println("Your account has been suspended");
    } else if (error.contains("Subscription expired")) {
        System.out.println("Your subscription has expired");
    } else {
        System.out.println("Error: " + error);
    }
}

Notes

Java Version

Requires Java 11+ for HttpClient. For Java 8, use HttpURLConnection instead.

JSON Parsing

The SDK uses regex for lightweight JSON parsing. For production, consider using Gson or Jackson for robust parsing.

Thread Safety

HttpClient is thread-safe, but the SDK instance stores state. Synchronize access if sharing between threads.

Obfuscation

Use ProGuard or R8 to obfuscate your app before distribution to protect embedded credentials.