[PR #164] [MERGED] Microsoft account (c): launcher sign-in, keychain, session handoff to the game #2368

Closed
opened 2026-11-02 15:55:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/164
Author: @ludovic111
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @ludovic111

Base: main ← Head: feat/msa-launcher


📝 Commits (4)

  • 82bee83 Launcher: Microsoft account sign-in, keychain and the game's session
  • 324eb28 Launcher README: Microsoft accounts
  • 6bed9b9 launcher.yml: build in HORIZON_MSA_CLIENT_ID from the repository variable
  • d4e0dc4 Settings subtitle mentions accounts

📊 Changes

11 files changed (+1745 additions, -12 deletions)

View changed files

📝 .github/workflows/launcher.yml (+3 -0)
📝 launcher/Cargo.lock (+41 -1)
📝 launcher/Cargo.toml (+12 -0)
📝 launcher/README.md (+24 -3)
➕ launcher/src/account.rs (+815 -0)
➕ launcher/src/account/tests.rs (+410 -0)
📝 launcher/src/backend.rs (+11 -1)
📝 launcher/src/cli.rs (+97 -0)
📝 launcher/src/lib.rs (+1 -0)
📝 launcher/src/main.rs (+258 -7)
📝 launcher/src/mcp.rs (+73 -0)

📄 Description

What

Part (c) of Microsoft account support (design note: docs/microsoft-account.md, in #161). The launcher signs players in with their Microsoft account and hands the session to the game.

  • launcher/src/account.rs, the sign-in chain:
    • OAuth 2.0 device code (consumers tenant, scope XboxLive.signin offline_access), polling with authorization_pending/slow_down.
    • Then Xbox Live user token → XSTS (with messages for the XErr codes) → login_with_xbox → entitlements (game_minecraft/product_minecraft) → profile (UUID, name, active skin and cape).
    • Clear messages for: declined, expired, not owned, no profile, and app not approved by Mojang yet.
  • Refresh: the Minecraft token is renewed from the Microsoft refresh token when it has less than an hour left, before each launch. A revoked refresh token says "Your Microsoft sign-in expired. Sign in again."
  • Keychain:
    • The SecretStore trait has three backends: the Secret Service through oo7 on Linux (the same build gpui already uses, so no new D-Bus stack), Keychain on macOS and Credential Manager on Windows (both through keyring 3), and memory for tests.
    • With no keychain, secrets stay in memory and the launcher says so.
    • accounts.json holds only names and UUIDs. Several accounts can be signed in, and one is selected (none = offline, as today).
  • Session handoff: a session-<random>.json is written with create_new and mode 0600 in the game home's sessions/, and passed as --session-file. The game (#161) refuses the file if it is older than 2 minutes and deletes it on read, so the token never appears on the command line. Stale leftovers are cleaned up.
  • UI, in the launcher's design language:
    • Settings has Accounts rows ("Plays" / "Signed in", Play as, Play offline, Sign out), "Sign in with Microsoft", and the code in large mono type with Copy code / Open link / Cancel.
    • The Play page has a "Playing as" row.
    • When the token can't be renewed (no network), the game still starts, offline, with a notice.
  • CLI: horizon-launcher account [list|sign-in|sign-out NAME|select NAME|offline] (--json for list). MCP: accounts, sign_in (returns the link and code for the player; the sign-in finishes in the background), sign_out, select_account. Tokens never appear in any output or Debug form.
  • Client ID is configuration: HORIZON_MSA_CLIENT_ID at build time (launcher.yml reads the repository variable vars.HORIZON_MSA_CLIENT_ID), and the same variable at run time overrides it. Empty or unset shows "Microsoft sign-in is not configured yet". No other app's client ID is used anywhere.

How tested

  • cargo test --lib account (macOS, Mac mini): 7 tests against a local mock of the Microsoft, Xbox Live, XSTS and Minecraft endpoints (recorded response shapes, mock tokens only):
    • the whole chain, including two pending polls and the exact request order;
    • refresh only when the token runs out, and a revoked refresh token;
    • XErr, not-owned and no-profile messages;
    • an unreachable service gives a message, not a URL;
    • cancelling the wait;
    • secrets only in the store (accounts.json has none) and sign-out removes them;
    • session files are 0600, complete, uniquely named, without the refresh token;
    • client ID configuration.
      Clippy is clean.
  • Linux (ThinkPad, NixOS): clippy is clean, with the oo7 Secret Service backend compiled, and the same 7 tests pass. The debug build was run on vscreen with a scratch HORIZON_LAUNCHER_HOME, HORIZON_NO_KEYCHAIN=1 and a placeholder client ID (Sign in was never clicked):
    • the Play page shows "Playing as Notch (Microsoft account)";
    • Settings shows the account row ("Plays", Play offline, Sign out), "Sign in with Microsoft" and the no-keychain note;
    • Play offline saves selected: null and switches the row to "Play as";
    • with no client ID, Settings shows "Microsoft sign-in is not configured yet…".
  • Windows (keyring windows-native) was not built: launcher.yml runs only when started by hand.
  • No real Microsoft account was used, and nothing was sent to Microsoft.

Label

skip-release: sign-in does nothing until the client ID below is set. Relabel it feature (or put it in the release after the variable is set) when sign-in actually works.

Needs Ludovic

  1. Azure app registration (portal.azure.com → App registrations):
    • personal Microsoft accounts only;
    • Authentication → Allow public client flows: Yes (device code);
    • no secret, no API permissions to add (scopes requested at sign-in: XboxLive.signin offline_access).
  2. Minecraft API access for that client ID: Mojang's review form (https://aka.ms/mce-reviewappid). Until it is approved, login_with_xbox answers 403 and the launcher says the app is not approved by Mojang yet.
  3. Set the repository variable (not a secret) HORIZON_MSA_CLIENT_ID to the Application (client) ID. The next launcher release builds it in.

Details are in docs/microsoft-account.md → "What Ludovic registers".

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/164 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/msa-launcher` --- ### 📝 Commits (4) - [`82bee83`](https://github.com/horizon-rust/horizon/commit/82bee83dc5176ad01bd941cf8731e345e1ca9adf) Launcher: Microsoft account sign-in, keychain and the game's session - [`324eb28`](https://github.com/horizon-rust/horizon/commit/324eb2836c588fc40412e463845c92070b5d02de) Launcher README: Microsoft accounts - [`6bed9b9`](https://github.com/horizon-rust/horizon/commit/6bed9b92caac62e29a1e462b9123d6ac321cf024) launcher.yml: build in HORIZON_MSA_CLIENT_ID from the repository variable - [`d4e0dc4`](https://github.com/horizon-rust/horizon/commit/d4e0dc49177a10d28bbddc4f79720ade32fdfe24) Settings subtitle mentions accounts ### 📊 Changes **11 files changed** (+1745 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/launcher.yml` (+3 -0) 📝 `launcher/Cargo.lock` (+41 -1) 📝 `launcher/Cargo.toml` (+12 -0) 📝 `launcher/README.md` (+24 -3) ➕ `launcher/src/account.rs` (+815 -0) ➕ `launcher/src/account/tests.rs` (+410 -0) 📝 `launcher/src/backend.rs` (+11 -1) 📝 `launcher/src/cli.rs` (+97 -0) 📝 `launcher/src/lib.rs` (+1 -0) 📝 `launcher/src/main.rs` (+258 -7) 📝 `launcher/src/mcp.rs` (+73 -0) </details> ### 📄 Description ## What Part (c) of Microsoft account support (design note: `docs/microsoft-account.md`, in #161). The launcher signs players in with their Microsoft account and hands the session to the game. - `launcher/src/account.rs`, the sign-in chain: - OAuth 2.0 device code (`consumers` tenant, scope `XboxLive.signin offline_access`), polling with `authorization_pending`/`slow_down`. - Then Xbox Live user token → XSTS (with messages for the `XErr` codes) → `login_with_xbox` → entitlements (`game_minecraft`/`product_minecraft`) → profile (UUID, name, active skin and cape). - Clear messages for: declined, expired, not owned, no profile, and app not approved by Mojang yet. - Refresh: the Minecraft token is renewed from the Microsoft refresh token when it has less than an hour left, before each launch. A revoked refresh token says "Your Microsoft sign-in expired. Sign in again." - Keychain: - The `SecretStore` trait has three backends: the Secret Service through `oo7` on Linux (the same build gpui already uses, so no new D-Bus stack), Keychain on macOS and Credential Manager on Windows (both through `keyring` 3), and memory for tests. - With no keychain, secrets stay in memory and the launcher says so. - `accounts.json` holds only names and UUIDs. Several accounts can be signed in, and one is selected (none = offline, as today). - Session handoff: a `session-<random>.json` is written with `create_new` and mode 0600 in the game home's `sessions/`, and passed as `--session-file`. The game (#161) refuses the file if it is older than 2 minutes and deletes it on read, so the token never appears on the command line. Stale leftovers are cleaned up. - UI, in the launcher's design language: - Settings has Accounts rows ("Plays" / "Signed in", Play as, Play offline, Sign out), "Sign in with Microsoft", and the code in large mono type with Copy code / Open link / Cancel. - The Play page has a "Playing as" row. - When the token can't be renewed (no network), the game still starts, offline, with a notice. - CLI: `horizon-launcher account [list|sign-in|sign-out NAME|select NAME|offline]` (`--json` for list). MCP: `accounts`, `sign_in` (returns the link and code for the player; the sign-in finishes in the background), `sign_out`, `select_account`. Tokens never appear in any output or `Debug` form. - Client ID is configuration: `HORIZON_MSA_CLIENT_ID` at build time (launcher.yml reads the repository variable `vars.HORIZON_MSA_CLIENT_ID`), and the same variable at run time overrides it. Empty or unset shows "Microsoft sign-in is not configured yet". No other app's client ID is used anywhere. ## How tested - `cargo test --lib account` (macOS, Mac mini): 7 tests against a local mock of the Microsoft, Xbox Live, XSTS and Minecraft endpoints (recorded response shapes, mock tokens only): - the whole chain, including two pending polls and the exact request order; - refresh only when the token runs out, and a revoked refresh token; - XErr, not-owned and no-profile messages; - an unreachable service gives a message, not a URL; - cancelling the wait; - secrets only in the store (accounts.json has none) and sign-out removes them; - session files are 0600, complete, uniquely named, without the refresh token; - client ID configuration. Clippy is clean. - Linux (ThinkPad, NixOS): clippy is clean, with the `oo7` Secret Service backend compiled, and the same 7 tests pass. The debug build was run on vscreen with a scratch `HORIZON_LAUNCHER_HOME`, `HORIZON_NO_KEYCHAIN=1` and a placeholder client ID (Sign in was never clicked): - the Play page shows "Playing as Notch (Microsoft account)"; - Settings shows the account row ("Plays", Play offline, Sign out), "Sign in with Microsoft" and the no-keychain note; - Play offline saves `selected: null` and switches the row to "Play as"; - with no client ID, Settings shows "Microsoft sign-in is not configured yet…". - Windows (`keyring` windows-native) was not built: launcher.yml runs only when started by hand. - No real Microsoft account was used, and nothing was sent to Microsoft. ## Label `skip-release`: sign-in does nothing until the client ID below is set. Relabel it `feature` (or put it in the release after the variable is set) when sign-in actually works. ## Needs Ludovic 1. **Azure app registration** (portal.azure.com → App registrations): - personal Microsoft accounts only; - Authentication → **Allow public client flows: Yes** (device code); - no secret, no API permissions to add (scopes requested at sign-in: `XboxLive.signin offline_access`). 2. **Minecraft API access** for that client ID: Mojang's review form (https://aka.ms/mce-reviewappid). Until it is approved, `login_with_xbox` answers 403 and the launcher says the app is not approved by Mojang yet. 3. Set the repository **variable** (not a secret) `HORIZON_MSA_CLIENT_ID` to the Application (client) ID. The next launcher release builds it in. Details are in `docs/microsoft-account.md` → "What Ludovic registers". 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:55:22 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2368
No description provided.