Continue with Codai ID

If your game has its own Codai ID account system (it has its own OIDC client at Codai ID), a player who is signed in to the store can continue in your game with one tap and no password, after they agreed once. The store signs in with Codai ID, so it knows the player's Codai ID user id; the ticket below hands exactly that id, and the display name, to your declared server, which maps it to the game's account. Nothing happens without the player's consent, and it works for any studio whose game uses Codai ID.

What you do #

  1. Declare your server in servers (Game servers): the ticket is made out to one of them.
  2. Declare your Codai ID client in velox.json (codaiId):
{
  "servers": [
    {
      "origin": "https://clankmates.codai.app",
      "purpose": { "en": "Accounts, friends and matchmaking", "de": "Konten, Freunde und Matchmaking" },
      "operator": "Codai",
      "privacy": "https://codai.app/privacy"
    }
  ],
  "codaiId": { "clientId": "clankmates-web" }
}

clientId is the OIDC client id your game uses at Codai ID. velox verify refuses a codaiId without a declared server. Like servers it belongs to the build: a new client id is a new build, and players are asked again.

  1. In the game, ask for a ticket when the player wants to continue with Codai ID, send it to your server and have the server verify it:
const ticket = await velox.auth.getCodaiIdTicket("https://clankmates.codai.app");  // a string, or null
if (ticket) {
  const res = await fetch("https://clankmates.codai.app/auth/velox", { method: "POST", headers: { Authorization: `Bearer ${ticket}` } });
  // your server answers with its own session for the player's game account
} else {
  // a guest, "Not now", withdrawn, no signing key: show your normal sign-in
}

getCodaiIdTicket(audience) is a separate call from getTicket, on purpose: it asks for the player's real Codai ID identity, so it is only answered after the consent below, and its ticket is a different kind of token. It never rejects; null means "carry on with your own sign-in". Offer it as a button ("Continue with Codai ID"), not on load: the player sees a question from the store when you ask.

What the player sees #

The first time the game asks, the player page (never your game) opens a dialog: "<Game> by <studio> wants to use your Codai ID account <display name>. It receives your Codai ID user id and display name." with the declared servers and a link to their privacy information, and Allow / Not now. It is a modal dialog the keyboard and screen readers can use, in English and German. Your game waits for the answer; it cannot show, answer or fake the dialog, and nothing a game does records a consent.

  • Allow records the consent for this account and this game (when, which Codai ID client, which wording) and the ticket is issued at once.
  • Not now answers null. If the game asks again within 30 seconds it is told no without the dialog; later the player is asked again.
  • The consent holds until the player withdraws it under Account, Connected games (or deletes the account), until the build names another client id or the wording of the dialog changes, or until the game has not used it for 24 months. A withdrawal stops new tickets; one already issued stays valid for its five minutes.
  • It is per game. Allowing one game says nothing about another.

This is the whole legal basis for handing a second service the account id: without the player's consent the store never issues the ticket, and there is no automatic linking. You are the controller for what your game and server do with the id and the name afterwards; your privacy policy has to say so.

The ticket #

A compact JWS signed with the store's keys (EdDSA or ES256, the same key set as the player ticket, published at <store origin>/.well-known/jwks.json), valid 5 minutes. The header is { "alg": "EdDSA", "typ": "velox-codai-id+jwt", "kid": "..." }; the claims:

claim
issthe store's public origin
audyour server's origin, as the game asked for it. Accept only a ticket made out to you.
subthe player's Codai ID user id: the OIDC sub Codai ID gave this account, the same id your game's own Codai ID sign-in returns. Key the game account on it.
codai_clientyour Codai ID client id (codaiId.clientId). Accept only your own.
namethe player's Codai ID username (the one name Velox shows for them; they change it at Codai ID)
gameyour game's slug
vtypalways "codai-id": the type of this ticket
iat, expseconds; exp = iat + 300
jtia unique id; remember it for five minutes if a ticket should work once

There is no e-mail and no role in it. A normal ticket (getTicket) has a g_... pseudonym as sub and no vtyp; the two kinds cannot be mistaken for each other. The verifier of one refuses the other (wrong_type), and a server must only ever accept the kind it asked for.

Verify it on your server #

Never trust the game: the ticket proves it, and only your server can check it. With the package (@velox/protocol, subpath ticket):

import { verifyVeloxCodaiIdTicket } from "@velox/protocol/ticket";

const r = await verifyVeloxCodaiIdTicket(token, {
  issuer: "https://store.example",                 // the store the game runs on
  audience: "https://clankmates.codai.app",        // this server's declared origin
  clientId: "clankmates-web",                      // your codaiId.clientId
});
if (!r.ok) return new Response("unauthorized", { status: 401 });   // r.code says why
const { sub, name } = r.claims;                    // sub = the player's Codai ID user id

It checks the signature against the key set (fetched from the store, cached, refetched once on an unknown kid), the algorithm against the key, iss, aud, the time, the ticket type and your client id, and never throws. The codes are malformed, bad_algorithm, unknown_key, bad_signature, wrong_issuer, wrong_audience, expired, not_yet_valid, too_long_lived, no_keys, wrong_type and wrong_client.

Without the package, follow the plain WebCrypto verifier in Game servers and add three checks on the claims: vtyp === "codai-id", the header's typ === "velox-codai-id+jwt", and codai_client equals your client id.

Map it to the game account #

sub is the Codai ID user id, so the account your game already keeps for a player who signs in with Codai ID directly has the same id: look it up by sub.

  1. An account for sub exists: that is the player. Start the game's own session for it.
  2. None exists: this is the player's first visit. Create the account (take the name from name, or let them change it), store sub as its Codai ID subject, and start the session. They agreed to this in the store's dialog.
  3. Never match on name, and never create a second account for a sub you already have.

Your server issues its own session afterwards (a cookie, a token of your own): the ticket is not a session and carries no Codai ID access token, so the game cannot call other Codai services as the player. If a game needs more than the id and the name, the player signs in with Codai ID in your game the normal way.

Two things to know when you test:

  • Against a development store (velox dev stack) sign-in is not Codai ID, so sub is a development id such as dev:ada; the shape is the same.
  • The ticket needs the store's signing key; a store without one answers null (Game servers).

Withdrawal and deletion #

The player withdraws under Account, Connected games; tickets stop at once. What your server already stores about the player is yours: offer deletion in the game, and delete the game account when the Codai ID account is deleted (Codai ID tells connected services). The store erases its consent records with the account and lists them in the player's data export.