mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-24 04:43:47 +00:00
> **Maintainer note:** part of the private OpenFront Steam release (Milestone 2, tracked in Linear), not a public GitHub issue. Per the contributor policy this needs an approved/assigned issue or a maintainer label to avoid auto-close — flagging for a maintainer to handle. Resolves: _n/a — private Steam-release work (see note above)_ ## Description: Adds the client-side pieces for authenticating the OpenFront **Steam desktop build** (an Electron shell) against the existing API, mirroring the established CrazyGames integration. The native Steamworks code lives in the desktop shell and is exposed to this client through a `window.openfrontDesktop.steam` bridge; this PR is the renderer half. - **`SteamSDK.ts`** (new) — thin wrapper over the desktop shell's Steam bridge (`isOnSteam` / `getTicket` / `getUser`), mirroring `CrazyGamesSDK`; narrows the loosely-typed `window.openfrontDesktop` locally rather than re-declaring it. - **`Auth.ts`** — a Steam branch at the top of `doRefreshJwt()` plus `doSteamLogin()`, exchanging a Steam Web-API ticket at `POST /auth/steam` for a session JWT, exactly paralleling `doCrazyGamesLogin`. Re-exchanges on expiry (the refresh cookie is cross-site-blocked from the `app://` origin); no ticket / not on Steam falls through to the existing flow. - **`Api.ts`** — `getAudience()` now sources from `BOOTSTRAP_CONFIG` (`ClientEnv.jwtAudience()`) instead of `window.location`, so the desktop app (running at `app://openfront`) resolves the real API base. Behavior-preserving on web, where the injected audience already equals the hostname-derived one. - **`UsernameInput.ts`** — seeds the in-game display name from the Steam persona on first launch and persists it (unlike CrazyGames). Writes only the local display name; never the account username. - **`SteamLinkSignpost.ts`** (new) — a one-time, dismissible notice shown on first Steam launch that account linking is coming. ## Please complete the following: - [ ] I have added screenshots for all UI updates — ⚠️ _the new first-launch link signpost is a UI addition; it renders only inside the Steam desktop shell. Screenshots to be added by the maintainer._ - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file — signpost strings go through `translateText()` with keys added to `resources/lang/en.json` (`steam.link_signpost`, `common.got_it`). - [x] I have added relevant tests to the test directory — unit tests for `SteamSDK` (incl. bridge-throws degradation), the `Auth.ts` Steam exchange + fall-through, the `Api.ts` audience change, username seeding, and the signpost gating. Full suite green (1976) + `tsc --noEmit` clean. ## Please put your Discord username so you can be contacted if a bug or regression is found: _⚠️ maintainer to fill_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01BWxUzYb2uqjcBFQuNSJhMy
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import { getApiBase, getAudience } from "../src/client/Api";
|
|
import { ClientEnv } from "../src/client/ClientEnv";
|
|
|
|
function setConfig(jwtAudience: string) {
|
|
(window as any).BOOTSTRAP_CONFIG = {
|
|
gameEnv: "prod",
|
|
numWorkers: 1,
|
|
turnstileSiteKey: "x",
|
|
jwtAudience,
|
|
instanceId: "desktop",
|
|
gitCommit: "test",
|
|
};
|
|
ClientEnv.reset();
|
|
}
|
|
|
|
// setConfig sets window.BOOTSTRAP_CONFIG; clear it (and the cached env) after
|
|
// every test so a stray value can't leak into a later test.
|
|
afterEach(() => {
|
|
delete (window as any).BOOTSTRAP_CONFIG;
|
|
ClientEnv.reset();
|
|
});
|
|
|
|
describe("getApiBase localhost fallback", () => {
|
|
beforeEach(() => {
|
|
localStorage.clear();
|
|
// getAudience() now reads the audience from BOOTSTRAP_CONFIG, so the
|
|
// localhost branch is reached via jwtAudience "localhost".
|
|
setConfig("localhost");
|
|
});
|
|
|
|
// API_DOMAIN is forced empty under vitest via the vite.config `define`, so this
|
|
// regression test exercises the fallback branch deterministically regardless of
|
|
// any API_DOMAIN in the host shell / CI.
|
|
it("falls back to http://localhost:8787 on localhost when apiHost is not set and API_DOMAIN is empty", () => {
|
|
expect(getApiBase()).toBe("http://localhost:8787");
|
|
});
|
|
});
|
|
|
|
describe("getAudience / getApiBase from BOOTSTRAP_CONFIG", () => {
|
|
beforeEach(() => ClientEnv.reset());
|
|
|
|
it("returns the configured audience (desktop staging)", () => {
|
|
setConfig("openfront.dev");
|
|
expect(getAudience()).toBe("openfront.dev");
|
|
expect(getApiBase()).toBe("https://api.openfront.dev");
|
|
});
|
|
|
|
it("returns the configured audience (prod)", () => {
|
|
setConfig("openfront.io");
|
|
expect(getAudience()).toBe("openfront.io");
|
|
expect(getApiBase()).toBe("https://api.openfront.io");
|
|
});
|
|
});
|