Authentication
Client authentication via access token with validation against the Master Server.
The Authentication message allows clients to authenticate with the Relay server using an access token.
It validates the client's identity against the Master Server and establishes a user session.
Priority
High - This message has a high priority to allow quick access to features.
The Authentication message requires the client to have completed the Handshake. Requests sent before the handshake will be ignored by the server.
Client → Server Request
Payload Format
[flags: byte]
[access_token: string]Detailed Structure
| Type | Name | Description |
|---|---|---|
| byte | Flags | Authentication options |
| string | AccessToken | Access token provided by the authentication system |
Auth Flags
| Value | Name | Description |
|---|---|---|
| 0x00 | None | Standard authentication |
| 0x01 | UseIntegrity | Uses an integrity token instead of a bearer token |
| 0x02 | UseGuest | Guest access attempt (not supported) |
Payload Example
[0x00] // Flags = None
[0x20, "eyJhbGciOiJIUzI1NiIs..."] // AccessToken (32 chars)Authentication with Integrity
[0x01] // Flags = UseIntegrity
[0x28, "integrity_token_here..."] // Integrity token (40 chars)Server → Client Response
Payload Format
[result: byte]
(Success == result ? (
[user_id: uint]
[server_address: string]
[display_name: string]
))
(Blacklisted == result ? [expire_at: DateTime])
(Error in result ? [reason?: string])Detailed Structure
| Type | Name | Description |
|---|---|---|
| byte | Result | Authentication result code |
| uint | UserID | Unique user ID (on success) |
| string | ServerAddress | User's server address (on success) |
| string | DisplayName | User's display name (on success) |
| DateTime | ExpireAt | Ban expiration timestamp (if blacklisted) |
| string | Reason | Ban reason or error message |
Auth Results
| Value | Name | Description |
|---|---|---|
| 0x00 | Success | Authentication successful |
| 0x01 | InvalidToken | Invalid or expired access token |
| 0x02 | MasterError | Communication error with the Master Server |
| 0x03 | Blacklisted | Banned user |
| 0x04 | Unknown | Unknown error |
Response Example - Success
[0x00] // Result = Success
[0x00, 0x00, 0x04, 0x2A] // UserID = 1066
[0x0A, "nox.server"] // ServerAddress = "nox.server"
[0x0C, "PlayerName123"] // DisplayName = "PlayerName123"Response Example - Invalid Token
[0x01] // Result = InvalidTokenResponse Example - Blacklisted
[0x03] // Result = Blacklisted
[0x00, 0x00, 0x01, 0x8A, 0x32, 0x1F, 0x80, 0x00] // ExpireAt (timestamp)
[0x0F, "Cheating detected"] // Reason = "Cheating detected"Response Example - Master Error
[0x02] // Result = MasterError
[0x14, "Database unavailable"] // ErrorMessage = "Database unavailable"Processing
Server Side
- State validation: Check that the client has completed the handshake
- Flags reading: Process the authentication options
- Token validation: Check that the token is not empty
- Master request: Validate against the Master Server via
/api/relays/checkbearer - Response processing: Assign user information or handle errors
Client Side
- Data preparation: Assemble the flags and the token
- Request sending: Transmit to the server
- Response processing: Store user information or handle errors
Special Behaviors
Token Types
- Bearer Token (default): Standard access token
- Integrity Token: Specialized token for integrity checks
Error Handling
- Invalid token: Returns
InvalidToken - Network error: Returns
MasterErrorwith the error message - Banned user: Returns
Blacklistedwith the expiration date and the reason. If the expiration date is in the past (for example, 0x00), the client must handle the error as a permanent ban.
Error Codes
Failed Authentication
If authentication fails, the client may attempt a new authentication with a different token or handle the error according to the received result code.
Connection Required
Authentication requires an active connection to the Master Server. If unavailable, a MasterError will be returned.