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.
| What | Value |
|---|---|
| Provider (discovery) | https://account.classic-strike.com/openid |
| Endpoint | https://account.classic-strike.com/openid/login |
| A player's identity | https://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
-
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_tomust be under it -
openid.identityandopenid.claimed_id: bothhttp://specs.openid.net/auth/2.0/identifier_select
-
- The player signs in if needed, sees your site's host name and agrees, or cancels.
-
The player comes back to
openid.return_towithopenid.mode=id_resand the signed answer, or withopenid.mode=cancel. -
Your server checks the answer: it posts every
openid.*field it got back to the endpoint, withopenid.modechanged tocheck_authentication. The reply is text;is_valid:truemeans the answer is genuine. -
Your server takes the CSID from
openid.claimed_id, after checking that it starts withhttps://account.classic-strike.com/openid/id/.
Rules to keep in mind:
- An answer can be checked once, within five minutes. Check it as soon as the player comes back.
-
Check that
openid.return_toin the answer is the page that received it, so an answer made for another site is refused. -
Use
httpsfor your site. Anhttpsite still works, but players are warned that it is not secure. -
Associations are not supported: libraries fall back to
check_authenticationby themselves. - Only the CSID comes back. Read the player's name and picture with the Web API (below).
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.
- Make the key on the account website, on the Web API page. It comes with the full game, on an account whose email is verified.
- Each account has one key; a new key stops the old one.
-
Keep the key on your server. A key with a website noted on it can also be used from that website's pages, with
?key=.
| Call | What 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();