Skip to main content

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.

info

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.

ODIN Access Key Generator

Click on the button to create an access key that you can use for free for up to 25 concurrent users.

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.

Node.js Token Server

This is a simple Node.js server application that generates room tokens for your clients to access the 4Players ODIN. More info and the full project can be found on GitHub.

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

// replace the accessKey with your own, if you want to generate tokens for testing purposes.
const accessKey = '__YOUR_ACCESS_KEY__';
const generator = new TokenGenerator(accessKey);

const hostname = '0.0.0.0';
const port = 8080;

function onRequest(req: IncomingMessage, res: ServerResponse): void {
const url = new URL(req.url ?? '/', `http://${req.headers.host ?? 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}" }`);
res.end();
}

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

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