English
Sign in

Websites: sign-in and the Web API

A community website, a stats page or a tool can sign players in with their Classic Strike account and read their public data. Nothing has to be registered or approved: any website can start right away.

Sign in through Classic Strike

Players sign in on the Classic Strike account website and come back to your site with their CSID. It is OpenID 2.0, the same protocol many sites already use for other game accounts, so an OpenID 2.0 library works as it is.

WhatValue
Provider (discovery)https://account.classic-strike.com/openid
Endpointhttps://account.classic-strike.com/openid/login
A player's identityhttps://account.classic-strike.com/openid/id/<16 characters>

The 16 characters at the end of the identity are the player's CSID without CSID: in front.

The steps

  1. Your site sends the player to the endpoint with these fields in the query:
    • openid.ns=http://specs.openid.net/auth/2.0
    • openid.mode=checkid_setup
    • openid.return_to: the page of your site the player comes back to
    • openid.realm: your site's address; openid.return_to must be under it
    • openid.identity and openid.claimed_id: both http://specs.openid.net/auth/2.0/identifier_select
  2. The player signs in if needed, sees your site's host name and agrees, or cancels.
  3. The player comes back to openid.return_to with openid.mode=id_res and the signed answer, or with openid.mode=cancel.
  4. Your server checks the answer: it posts every openid.* field it got back to the endpoint, with openid.mode changed to check_authentication. The reply is text; is_valid:true means the answer is genuine.
  5. Your server takes the CSID from openid.claimed_id, after checking that it starts with https://account.classic-strike.com/openid/id/.

Rules to keep in mind:

Node.js (no library)

// Node 18 or newer. Start: send the player to signInUrl(). Back: verify(url).
const OP = "https://account.classic-strike.com/openid/login";
const NS = "http://specs.openid.net/auth/2.0";
const SELECT = NS + "/identifier_select";
const ID_PREFIX = "https://account.classic-strike.com/openid/id/";

export function signInUrl(returnTo, realm) {
  const q = new URLSearchParams({
    "openid.ns": NS, "openid.mode": "checkid_setup",
    "openid.return_to": returnTo, "openid.realm": realm,
    "openid.identity": SELECT, "openid.claimed_id": SELECT,
  });
  return `${OP}?${q}`;
}

// The full address the player came back to; the CSID, or null.
export async function verify(backUrl) {
  const back = new URL(backUrl);
  const p = back.searchParams;
  if (p.get("openid.mode") !== "id_res") return null;
  let rt;
  try { rt = new URL(p.get("openid.return_to") ?? ""); } catch { return null; }
  if (rt.origin + rt.pathname !== back.origin + back.pathname) return null;
  const form = new URLSearchParams();
  for (const [k, v] of p) if (k.startsWith("openid.")) form.set(k, v);
  form.set("openid.mode", "check_authentication");
  const r = await fetch(OP, { method: "POST", body: form });
  if (!(await r.text()).split("\n").includes("is_valid:true")) return null;
  const id = p.get("openid.claimed_id") ?? "";
  const m = id.startsWith(ID_PREFIX) && /^[A-Z2-7]{16}$/.exec(id.slice(ID_PREFIX.length));
  return m ? "CSID:" + m[0] : null;
}

PHP (no library)

<?php
// Start: header("Location: " . cs_sign_in_url($returnTo, $realm));
// Back: $csid = cs_verify($returnTo); (null when the answer is not valid)
const CS_OP = "https://account.classic-strike.com/openid/login";
const CS_ID = "https://account.classic-strike.com/openid/id/";

function cs_sign_in_url(string $returnTo, string $realm): string {
    $select = "http://specs.openid.net/auth/2.0/identifier_select";
    return CS_OP . "?" . http_build_query([
        "openid.ns" => "http://specs.openid.net/auth/2.0",
        "openid.mode" => "checkid_setup",
        "openid.return_to" => $returnTo,
        "openid.realm" => $realm,
        "openid.identity" => $select,
        "openid.claimed_id" => $select,
    ]);
}

function cs_verify(string $returnTo): ?string {
    // PHP turns the dots of the field names into underscores in $_GET.
    $fields = [];
    foreach (explode("&", $_SERVER["QUERY_STRING"] ?? "") as $pair) {
        [$k, $v] = array_map("urldecode", explode("=", $pair, 2) + [1 => ""]);
        if (str_starts_with($k, "openid.") && !isset($fields[$k])) $fields[$k] = $v;
    }
    if (($fields["openid.mode"] ?? "") !== "id_res") return null;
    $path = fn($u) => strtok($u, "?");
    if ($path($fields["openid.return_to"] ?? "") !== $path($returnTo)) return null;
    $fields["openid.mode"] = "check_authentication";
    $ctx = stream_context_create(["http" => [
        "method" => "POST",
        "header" => "Content-Type: application/x-www-form-urlencoded",
        "content" => http_build_query($fields),
        "timeout" => 10,
    ]]);
    $reply = @file_get_contents(CS_OP, false, $ctx);
    if ($reply === false || !in_array("is_valid:true", explode("\n", $reply), true)) return null;
    $id = $fields["openid.claimed_id"] ?? "";
    if (!str_starts_with($id, CS_ID)) return null;
    $csid = substr($id, strlen(CS_ID));
    return preg_match('/^[A-Z2-7]{16}$/', $csid) ? "CSID:" . $csid : null;
}

With an OpenID library

A library made for OpenID 2.0 sign-in through another game's accounts works when it is given https://account.classic-strike.com/openid as the provider. Read the CSID from the claimed identity it returns, after checking the prefix as above.

The Web API

The Web API gives players' public data: CSID, name and picture. It needs a key.

CallWhat it gives
GET https://account.classic-strike.com/v1/webapi/GetPlayerSummaries?csids=CSID:A,CSID:B{"players": [{"csid", "name", "avatar_url"}]}, up to 100 CSIDs a call; players that do not exist are left out
GET https://account.classic-strike.com/v1/webapi/ResolveName?name=N{"csids": [...]}: the players with exactly that name who let others find them

Send the key in the X-API-Key header. A player without a picture has the picture of none (/v1/avatars/none.png) as avatar_url.

Limits: 100 000 calls a key a day and 1 000 a minute. Past them the answer is 429 with Retry-After; a key that keeps calling is suspended. Every refused key gets the same 403.

const r = await fetch(
  "https://account.classic-strike.com/v1/webapi/GetPlayerSummaries?csids=" + encodeURIComponent(csid),
  { headers: { "X-API-Key": process.env.CS_WEBAPI_KEY } },
);
const { players } = await r.json();