Authentication

Understanding Hytale server OAuth2 authentication

Authentication

Hytale servers require OAuth2 authentication. This container implements the official Server Provider Authentication Guide for seamless, automated authentication.

How It Works

The container uses OAuth2 Device Code Flow (RFC 8628). On first run, you authorize once, and tokens are automatically managed thereafter.

One auth, used everywhere — The same OAuth token authenticates both the downloader and the game server.

Authentication Flow

First Startup

  1. Container requests a device code from Hytale OAuth
  2. A device authorization URL and code appear in the logs
  3. You complete authorization in your browser
  4. Tokens are saved and used for all subsequent operations

Token Usage

After authorization, tokens are used to:

  • Download server files via hytale-downloader
  • Create game sessions for the server
  • Authenticate the server with Hytale's services

Automatic Refresh

Tokens are automatically refreshed before expiry:

TokenLifetimeRefresh
OAuth Access Token1 hour5 min before expiry
OAuth Refresh Token30 days
Game Session1 hour5 min before expiry

Subsequent Restarts

On restart:

  1. Load existing tokens from storage
  2. Refresh if needed
  3. Create a new game session
  4. Start the server

Environment Variables

VariableDefaultDescription
AUTO_REFRESH_TOKENStrueRefresh tokens before expiry
AUTOSELECT_GAME_PROFILEtrueAuto-select first profile
HYTALE_SERVER_SESSION_TOKEN(empty)Pre-provided session token
HYTALE_SERVER_IDENTITY_TOKEN(empty)Pre-provided identity token

Profile Selection

If your account has multiple game profiles:

Automatic (Default)

With AUTOSELECT_GAME_PROFILE=true, the first profile is selected automatically.

Manual Selection

Set AUTOSELECT_GAME_PROFILE=false:

environment:
  AUTOSELECT_GAME_PROFILE: "false"

Then select a profile:

docker exec -it hytale-server hytale auth profile list
docker exec -it hytale-server hytale auth profile select 1

Profile selection is saved and persists across restarts.

Token Storage

Tokens are stored in /server/.hytale/tokens/ (in the volume):

FilePurpose
oauth_tokens.jsonOAuth access & refresh tokens
session_tokens.jsonGame session tokens
profiles.jsonCached user profiles
selected_profile.jsonCurrently selected profile

CLI Commands

# Check status
docker exec -it hytale-server hytale auth status

# Re-authenticate
docker exec -it hytale-server hytale auth login

# Refresh tokens
docker exec -it hytale-server hytale auth refresh

# List profiles
docker exec -it hytale-server hytale auth profile list

# Select profile
docker exec -it hytale-server hytale auth profile select 1

# Export tokens
docker exec -it hytale-server hytale auth export --json

# Clear all tokens
docker exec -it hytale-server hytale auth logout

For Hosting Providers

If you manage tokens externally, pass them via environment variables:

environment:
  HYTALE_SERVER_SESSION_TOKEN: "eyJhbGciOi..."
  HYTALE_SERVER_IDENTITY_TOKEN: "eyJhbGciOi..."

The container will skip OAuth and use these tokens directly.

Session tokens expire in 1 hour. Your system must refresh and restart containers with new tokens.

Troubleshooting

IssueSolution
Device code expiredRestart container for new code
Tokens not persistingCheck volume is mounted correctly
Need to re-authenticateRun hytale auth logout then restart
# Force re-auth
docker exec -it hytale-server hytale auth logout
docker compose restart

API Endpoints

The container implements these Hytale OAuth2 endpoints:

EndpointPurpose
POST /oauth2/device/authRequest device code
POST /oauth2/tokenExchange/refresh tokens
GET /my-account/get-profilesGet user profiles
POST /game-session/newCreate game session
POST /game-session/refreshRefresh game session

Base URLs:

  • OAuth: https://oauth.accounts.hytale.com
  • Account: https://account-data.hytale.com
  • Sessions: https://sessions.hytale.com

Next Steps

On this page