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.
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. It requires Node.js 22.12 or newer. The source code of the package, including a Deno version of this example, can be found on GitHub.
Create a new project and install the package:
Store your access key in a .env file next to the server, so it never ends up in your source code:
Start the server and open the URL it prints to get a token for the user john in the room my_room:
Since version 2.0 of @4players/odin-tokens, createToken() is asynchronous and returns a Promise. Make sure to
await it. Otherwise, your server responds with "[object Promise]" instead of a token and your clients fail to join
the room.