@tty-pt/axil-auth
Session management, user registration, credential verification, and terminal access gating for@tty-pt/axil. Canonical C headers:<ttypt/auth.h>,<ttypt/auth-config.h>, and<ttypt/auth-outcome.h>.
๐ Full C & Systems Documentation: See the main axil-auth GitHub README for HTTP endpoint contracts, multi-instance cookie isolation, and C module integration.
1. Overview & Domain Concepts
axil-auth (libaxil-auth.so / @tty-pt/axil-auth) provides complete HTTP authentication and session lifecycle management for the axil web server and Node.js applications:
- HTTP Authentication Lifecycle:
- Exposes
/auth/register,/auth/login,/auth/logout,/auth/confirm, and/auth/api/sessionendpoints when mounted inaxil.
- Multi-Instance Session Cookie Isolation:
- Issues
HttpOnly; SameSite=Laxsession cookies (QSESSIONorQSESSION_<port>) backed bylibcormsession tables, preventing collisions across multiple local daemon ports.
- Structured Outcome Codes (
<ttypt/auth-outcome.h>):
- Standardized status codes for registration, login, password updates, and token confirmation across SSR HTML forms and JSON API clients.
- POSIX & Terminal Gating Integration:
- Coordinates with
@tty-pt/axil-ttyvia jailed privilege-separated credential verification and HMAC-signed TTY tickets before allocating interactive PTY sessions.
2. Installation
npm config set @tty-pt:registry https://tty.pt/npm/
npm install @tty-pt/axil-auth
Native OS & Mobile Packages (tty.pt): Prebuilt native C packages (axil-auth) for Linux (apt, apk, pacman, dnf), macOS (brew), Windows (winget, MSYS2), and OpenBSD (pkg_add), plus static mobile sysroots for Android (https://tty.pt/android/) and iOS (https://tty.pt/ios/ โ libaxil-auth.xcframework) are available via the tty.pt package repositories.
3. Quickstart
Launch axil with Authentication Enabled
npx axil -d -p 8080 -m auth
Node.js Session & Credential Verification
import {
configure,
initAuth,
extractCookie,
getSessionUser,
verifyPassword,
usernameTaken,
getConfig,
getModulePath
} from "@tty-pt/axil-auth";
// 1. Configure session TTL and directories
configure({
cookieName: "QSESSION",
sessionTtl: 86400,
routePrefix: "/auth"
});
initAuth();
// 2. Extract session token from HTTP Cookie header and resolve user
const token = extractCookie("QSESSION=8f9a2b3c4d5e; Path=/");
const user = token ? getSessionUser(token) : null;
console.log("Authenticated user:", user);
// 3. Check username availability & verify password
if (usernameTaken("alice")) {
const ok = verifyPassword("alice", "CorrectHorseBatteryStaple!");
console.log("Password valid:", ok);
}
console.log("Active config:", getConfig());
console.log("Bundled Xylem module:", getModulePath());
4. JavaScript / TypeScript API Reference
configure(options?: Partial<AuthConfig>): boolean: Updates authentication configuration (cookieName,cookieAttrs,etcDir,usersDir,homeDir,routePrefix,wwwGid,maxSessions,maxUsers,sessionTtl).getConfig(): AuthConfig: Returns the active authentication configuration object.initAuth(): boolean: Initializes the underlying authentication tables and storage directories.extractCookie(cookieHeader: string, cookieName?: string): string | null: Extracts the session token value from a raw HTTPCookieheader string.getSessionUser(token: string): string | null: Resolves an active session token to its authenticated username, ornullif expired/invalid.verifyPassword(username: string, password: string): boolean: Verifies plaintext credentials against the stored password hash (auth_password_matches).usernameTaken(username: string): boolean: Returnstrueif the username is already registered.getModulePath(): string | null: Returns the filesystem path to the prebuiltlibaxil-authmodule foraxil -m.hasNativeModule(): boolean/getNativeAuth(): Inspects or retrieves the loaded N-API binding.
5. C Development Headers & Native Integration
CFLAGS += -I./node_modules/@tty-pt/axil-auth/include
LDLIBS += -laxil-auth
License
BSD-2-Clause โ Copyright (c) 2026, Paulo Quirino <quirinpa@gmail.com>. See LICENSE.