Skip to main content

OAuth2 & Device Authentication

The Hytale authentication system uses OAuth2 Device Code Flow combined with a Session Service for server authentication.

note

The following code snippets are taken from the Alloy Server Engine, not from the official Java source.
All data, structures, and responses should remain the same from language to language.

Authentication Methods

  1. Method A (External Session): Using pre-obtained tokens via CLI or environment variables.
  2. Method B (Device Code Flow): Interactive OAuth where the user authenticates via a browser code.
  3. Method C (Session Re-use): Loading saved credentials from disk.

OAuth2 Endpoints

EndpointURL
Device Authhttps://oauth.accounts.hytale.com/oauth2/device/auth
Tokenhttps://oauth.accounts.hytale.com/oauth2/token
Sessionshttps://sessions.hytale.com
Account Datahttps://account-data.hytale.com

Client Configuration:

  • Client ID: hytale-server
  • Scopes: openid offline auth:server

Data Structures

OAuthTokens

struct OAuthTokens {
std::string accessToken;
std::string refreshToken;
std::chrono::system_clock::time_point expiresAt;

bool isExpired() const;
bool needsRefresh() const; // 5 min before expiry
};

GameSession

struct GameSession {
std::string sessionToken; // Bearer token for session management
std::string identityToken; // JWT identifying the server
std::string sessionId; // Extracted from JWT 'sub' claim
std::chrono::system_clock::time_point expiresAt;
};

Device Code Flow

1. Initiate Device Code

Request:

POST [https://oauth.accounts.hytale.com/oauth2/device/auth](https://oauth.accounts.hytale.com/oauth2/device/auth)
Content-Type: application/x-www-form-urlencoded

client_id=hytale-server&scope=openid+offline+auth:server

Response:

{
"device_code": "...",
"user_code": "ABCD-1234",
"verification_uri": "[https://hytale.com/device](https://hytale.com/device)",
"verification_uri_complete": "[https://hytale.com/device?code=ABCD-1234](https://hytale.com/device?code=ABCD-1234)",
"expires_in": 600,
"interval": 5
}

2. Poll for Token

The client must poll the token endpoint every interval seconds (default: 5s).

Request:

POST [https://oauth.accounts.hytale.com/oauth2/token](https://oauth.accounts.hytale.com/oauth2/token)
Content-Type: application/x-www-form-urlencoded

client_id=hytale-server&grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=<code>

Polling States:

ResponseAction
authorization_pendingContinue polling
slow_downIncrease interval by 5s
expired_tokenDevice code expired
access_deniedUser denied
SuccessParse token response

Success Response:

{
"access_token": "...",
"refresh_token": "...",
"expires_in": 3600
}