Developer Documentation

Token Server

Your access key is your unique authentication key to be used to generate room tokens for accessing the 4Players ODIN server network. Think of it as your individual username and password combination all wrapped up into a single non-comprehendable string of characters, and treat it with the same respect.

You can create an access key for up to 25 users below for free and without registration. Please contact us if you want to go into production or need more.

While you can create an unlimited number of access keys for your projects, we strongly recommend that you never put an access key in your client code. The following Node.js server application starts a basic HTTP server and utilizes our @4players/odin-tokens package to generate a room token to be used by your client to access a room.

You can find the full project for this example on GitHub.

Node.js Token Server
import { createServer, IncomingMessage, ServerResponse } from "http";
import { URL } from "url";
import { TokenGenerator } from "@4players/odin-tokens";

const apiKey = "<YOUR_API_KEY>";
const generator = new TokenGenerator(apiKey);

const hostname = "";
const port = 8080;

function onRequest(req: IncomingMessage, res: ServerResponse): void {
  const url = new URL(req.url ?? "/", `http://${ ?? hostname}`);
  const roomId = url.pathname.substr(1) || "default";
  const userId = url.searchParams.get("user_id") ?? "unknown";
  const token = generator.createToken(roomId, userId);
  console.log(`💡 new token for '${userId}' in '${roomId}'`);
  res.statusCode = 200;
  res.setHeader("content-type", "application/json");
  res.write(`{ "token": "${token}" }`);

createServer(onRequest).listen(port, hostname);

console.log(`🚀 on http://${hostname}:${port}/my_room?user_id=john`);