Requirements
Unique and non-deterministic
A random, unguessable value. Never the player ID, the account ID, an email, or anything derived from them.
At least 2 hours valid
Sliding-window expiry is preferred where your platform supports it — the token refreshes while the player is active.
Reusable for the whole session
Multiple API calls and client reloads use the same token. Single-use tokens break every reconnect.
No length limit
Any length is fine. An opaque random string or a signed JWT both work.
Choosing a format
- Opaque random token
- Signed JWT
A random identifier, with the session state in your store. Simple and instantly revocable.
Revoking is a single delete. Preferred when you already run a session store.
Validating it
Your/player callback receives the token and answers with the player’s identity:
Token validity and
accountId are separate concerns. The token identifies a session; the accountId identifies the player, for life. See Account ID.Lifetime in practice
Common mistakes
Using the player ID as the token
Using the player ID as the token
It is deterministic and permanent. Anyone who learns a player ID can open a session as that player, forever. Use random bytes.
Single-use tokens
Single-use tokens
The game reloads on reconnect, on rotation, on a resumed session. A token consumed by the first
/player call breaks the second one.Tokens shorter than the session
Tokens shorter than the session
A 15-minute token ends the round for anyone who steps away. Two hours is the floor; sliding expiry is better.