Dev's NoxDev's Nox
Relay Protocol

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

TypeNameDescription
byteFlagsAuthentication options
stringAccessTokenAccess token provided by the authentication system

Auth Flags

ValueNameDescription
0x00NoneStandard authentication
0x01UseIntegrityUses an integrity token instead of a bearer token
0x02UseGuestGuest 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

TypeNameDescription
byteResultAuthentication result code
uintUserIDUnique user ID (on success)
stringServerAddressUser's server address (on success)
stringDisplayNameUser's display name (on success)
DateTimeExpireAtBan expiration timestamp (if blacklisted)
stringReasonBan reason or error message

Auth Results

ValueNameDescription
0x00SuccessAuthentication successful
0x01InvalidTokenInvalid or expired access token
0x02MasterErrorCommunication error with the Master Server
0x03BlacklistedBanned user
0x04UnknownUnknown 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 = InvalidToken

Response 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

  1. State validation: Check that the client has completed the handshake
  2. Flags reading: Process the authentication options
  3. Token validation: Check that the token is not empty
  4. Master request: Validate against the Master Server via /api/relays/checkbearer
  5. Response processing: Assign user information or handle errors

Client Side

  1. Data preparation: Assemble the flags and the token
  2. Request sending: Transmit to the server
  3. 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 MasterError with the error message
  • Banned user: Returns Blacklisted with 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.

On this page