Skip to main content

Authentication Methods

XyraPanel supports two primary authentication methods:
  1. API Keys - For programmatic access and automation
  2. Session Cookies - For browser-based applications and web interfaces

API Key Authentication

API keys provide secure, long-lived authentication tokens for automated access to the XyraPanel API.

Creating an API Key

API keys can be created through the XyraPanel web interface:
  1. Navigate to Account Settings → API Keys
  2. Click Create API Key
  3. Set an expiration date (max 90 days, default 90 days)
  4. Copy your API key immediately - it will only be shown once

Using API Keys

API keys can be provided in two ways:

Custom Header

API Key Configuration

API keys are configured in server/utils/auth.ts:

API Key Properties

  • Length: 32 characters (default)
  • Storage: Hashed in database using bcrypt
  • Expiration: 90 days (default), configurable between 1-90 days
  • Permissions: Inherits user permissions
  • Revocation: Can be deleted at any time via the API or web interface

Security Best Practices

  • Store API keys securely in environment variables or secret managers
  • Never commit API keys to version control
  • Rotate API keys regularly (every 30-90 days)
  • Use separate API keys for different applications
  • Delete unused or compromised API keys immediately
Session cookies are automatically set when you log in through the web interface. These are ideal for browser-based applications.

Session Configuration

Sessions are configured via Better Auth:

Session Features

  • Multi-Session: Up to 5 concurrent sessions per user
  • Auto-Renewal: Sessions refresh automatically
  • Secure Cookies: HttpOnly, Secure (in production), SameSite=Lax
  • Session Management: View and revoke active sessions

Authentication Headers

When using API keys or sessions, all authenticated requests should include:

Authentication Errors

401 Unauthorized

Causes:
  • Missing or invalid API key
  • Expired API key
  • Missing or expired session

401 API Key Required

Causes:
  • Endpoint requires API key authentication specifically
  • Session cookies are not accepted for this endpoint

Example: Complete API Request

Example: Creating a Server

Managing API Keys Programmatically

List Your API Keys

Delete an API Key

Environment Variables

Authentication is configured via environment variables:
.env.example
The BETTER_AUTH_SECRET must be at least 32 characters in production. Generate one using:

Advanced: Admin API Key Permissions

Admin API keys can have granular permissions using Access Control Lists (ACL):
  • servers.read - List and view servers
  • servers.write - Create and update servers
  • users.read - View users
  • users.write - Manage users
  • nodes.read - View nodes
  • nodes.write - Manage nodes
These permissions are enforced via requireAdminApiKeyPermission() middleware.