Skip to content

Players on your server

Your game may have a server of its own. The play token tells it who the player is, signed by Playium; your server checks it offline with any JWT library.

The token

ClaimValue
algES256; the key is chosen by kid from the JWKS
isshttps://platformbackend-production-e04dbbd2.up.railway.app
audYour game's id. Check it: a token issued for another game must be refused.
subThe player's pseudonymous id in your game: the same every time for your game, different in every other game, never their account id. Key your data by it.
gidYour game’s id, the same as aud.
modelive, preview or dev. Keep test data apart from players' data.
jti, iat, expId, issued at, expires at. Tokens live a few minutes.

The public keys: https://platformbackend-production-e04dbbd2.up.railway.app/.well-known/jwks.json. Your game's id is on its page in the console, and in playium.gameId.

Sending the token from the game

await fetch('https://your-server.example/score', {
  method: 'POST',
  headers: { authorization: `Bearer ${await playium.token()}`, 'content-type': 'application/json' },
  body: JSON.stringify({ score }),
});

playium.token() renews the token first when it is about to expire. Keep it in memory; never store it or put it in a URL.

Node.js, with jose

server.js
import { createRemoteJWKSet, jwtVerify } from 'jose';

const jwks = createRemoteJWKSet(new URL('https://platformbackend-production-e04dbbd2.up.railway.app/.well-known/jwks.json'));

export async function playerOf(request) {
  const token = request.headers.authorization?.replace(/^Bearer /, '');
  const { payload } = await jwtVerify(token, jwks, {
    issuer: 'https://platformbackend-production-e04dbbd2.up.railway.app',
    audience: process.env.PLAYIUM_GAME_ID, // your game's id
    algorithms: ['ES256'],
  });
  return { id: payload.sub, mode: payload.mode };
}

Python, with PyJWT

server.py
import jwt

jwks = jwt.PyJWKClient("https://platformbackend-production-e04dbbd2.up.railway.app/.well-known/jwks.json")

def player_of(token: str) -> dict:
    key = jwks.get_signing_key_from_jwt(token)
    claims = jwt.decode(token, key.key, algorithms=["ES256"],
                        audience=GAME_ID, issuer="https://platformbackend-production-e04dbbd2.up.railway.app")
    return {"id": claims["sub"], "mode": claims["mode"]}

What you get, and what you do not

The player's id and their language. Never their display name or email address: a game that wants a name asks the player for one. Playium keeps the account, the credits and the payments.

Next: Testing