diff --git a/apps/evo-client/main.cpp b/apps/evo-client/main.cpp index 555ee98..c902476 100644 --- a/apps/evo-client/main.cpp +++ b/apps/evo-client/main.cpp @@ -252,6 +252,7 @@ int main(int argc, char** argv) try { evo::client::ConnectForm form; bool connect_now = false; bool cellular_trial = false; + std::string auth_profile; // ADR-0131: one saved login per --profile. for (int i = 1; i < argc; ++i) { const std::string_view arg{argv[i]}; if (arg == "--version") { // Build identity for tester reports (ADR-0086). @@ -267,7 +268,11 @@ int main(int argc, char** argv) try { start_fixture = true; else if (arg == "--cellular") cellular_trial = true; - else if (arg == "--connect" && i + 1 < argc) { + else if (arg == "--profile" && i + 1 < argc) { + auth_profile = argv[++i]; + if (auth_profile.empty() || !evo::client::auth_profile_valid(auth_profile)) + return 2; + } else if (arg == "--connect" && i + 1 < argc) { form.endpoint = argv[++i]; connect_now = true; } else if (arg == "--server-name" && i + 1 < argc) @@ -315,7 +320,7 @@ int main(int argc, char** argv) try { " [--layer water|nitrogen|...|heat|moisture]\n" " [--refresh-every 1..1000] [--pick X,Y] " "[--screenshot FILE.bmp --frames N]\n" - " [--controls FILE] [--show-controls]\n" + " [--controls FILE] [--show-controls] [--profile NAME]\n" "Without --fixture or --connect the launcher opens.\n", stderr); return 2; @@ -458,7 +463,7 @@ int main(int argc, char** argv) try { return nullptr; }; // ADR-0131 browser sign-in (Windows); elsewhere the panel offers manual grants only. - evo::client::AuthClient auth{evo::client::native_auth_platform()}; + evo::client::AuthClient auth{evo::client::native_auth_platform(auth_profile)}; bool auth_connect = false; // Connect when the requested grant arrives. auto grant_requested = std::chrono::steady_clock::time_point{}; int drawn_organisms = -1; diff --git a/deploy/kubernetes/region/dev-session-route/listener.yaml b/deploy/kubernetes/region/dev-session-route/listener.yaml index fbb8e17..0447d93 100644 --- a/deploy/kubernetes/region/dev-session-route/listener.yaml +++ b/deploy/kubernetes/region/dev-session-route/listener.yaml @@ -12,7 +12,7 @@ spec: env: - {name: REGION_SESSION, value: "dev"} - {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"} - - {name: REGION_SESSION_WINDOW, value: "dev-20261015T210523-51595:1792109123"} + - {name: REGION_SESSION_WINDOW, value: "dev-20261015T213553-53423:1792110953"} - {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"} ports: # QUIC (ADR-0090): UDP only; nothing listens on TCP 7400. diff --git a/docs/adr/0131-keycloak-login-and-grant-broker.md b/docs/adr/0131-keycloak-login-and-grant-broker.md index dfb338f..66aed63 100644 --- a/docs/adr/0131-keycloak-login-and-grant-broker.md +++ b/docs/adr/0131-keycloak-login-and-grant-broker.md @@ -82,7 +82,10 @@ never be minted on a client. listener on `127.0.0.1:47600` accepts exactly one `/callback` with that state and an `iss` of the realm, if present. The password never reaches the client. - The refresh token is stored only in Windows Credential Manager - (`AeternalisEvolution/DEV/refresh-token/v1`). Rotation removes the stored token + (`AeternalisEvolution/DEV/refresh-token/v1`, plus `/` for `--profile NAME`, + so several clients on one machine can hold different accounts). Authorization asks + for `prompt=login`: Keycloak ignores `select_account`, and reusing the browser's + single sign-on session would always pick the same account. Rotation removes the stored token before it is sent, so a lost reply ends the login instead of replaying a consumed token. Access tokens and grants stay in memory and are zeroed when dropped. - A grant reply is accepted only if its JSON agrees with the grant record: marker, diff --git a/docs/engineering/CLIENT.md b/docs/engineering/CLIENT.md index d9ef3fb..f76381c 100644 --- a/docs/engineering/CLIENT.md +++ b/docs/engineering/CLIENT.md @@ -31,7 +31,10 @@ short notifications expire and can be dismissed. After sign-in the client fetches a 10-minute grant from `grants.aeternalisgames.com` and connects to the cellular DEV region. It renews the grant before expiry and after a lost connection. **Play in DEV** reconnects while signed in. **Sign out** closes the -session and revokes the login. Only the region CA file is still read from the form. +session and revokes the login. `--profile NAME` keeps a separate saved login per +profile, so two clients on one machine can use two accounts; the browser always +shows the login form, so you choose the account. Start them one at a time: sign-in +uses loopback port 47600. Only the region CA file is still read from the form. The manual endpoint and grant-bundle fields stay under "Manual connection (developer grants)". diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index c2fc45c..cb42c85 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -7661,3 +7661,17 @@ genesis commit id. The region deployment, the provision Job, the life-route cata and the broker's default region and route name region 5. Region 4 and its history stay in the stores, unserved. Checked with `deploy-policy-check.py`; provisioning runs on the next full sync. + +## 2026-10-15 — client sign-in profiles (CI pending) + +Playtest finding: only one client per machine could sign in. The saved login lived +under one Credential Manager name, and Keycloak ignored `prompt=select_account`, so +the browser reused its single sign-on session. `--profile NAME` (1–32 of +`[A-Za-z0-9_-]`) gives each profile its own saved login under +`.../refresh-token/v1/`. The default name is unchanged. Authorization now +asks for `prompt=login`. + +Tests: `client-auth` covers profile validation, the credential names, the refusal +of an invalid profile, and `prompt=login` in the authorization URL. Executed +locally: WSL clang-19 `client-probe` with clang-tidy 14/14 plus the Xvfb X11 +lifecycle check; MSVC `client-package` 18/18; clang-format 19. diff --git a/include/evo/client/auth.hpp b/include/evo/client/auth.hpp index e22e7c5..64f8631 100644 --- a/include/evo/client/auth.hpp +++ b/include/evo/client/auth.hpp @@ -61,7 +61,13 @@ class AuthPlatform { [[nodiscard]] virtual bool save_refresh(std::string_view token) = 0; [[nodiscard]] virtual bool erase_refresh() = 0; }; -[[nodiscard]] std::unique_ptr native_auth_platform(); // Windows; null elsewhere. +// A sign-in profile keeps its own saved login, so several clients on one machine can +// use different accounts. Empty is the default profile; otherwise 1..32 of [A-Za-z0-9_-]. +[[nodiscard]] bool auth_profile_valid(std::string_view profile); +// The Credential Manager target for a profile. +[[nodiscard]] std::string auth_credential_name(std::string_view profile); +// Windows; null elsewhere or for an invalid profile. +[[nodiscard]] std::unique_ptr native_auth_platform(std::string_view profile = {}); [[nodiscard]] std::string auth_form_escape(std::string_view value); [[nodiscard]] std::string auth_base64url(std::span bytes); diff --git a/src/client/auth/client.cpp b/src/client/auth/client.cpp index eea78ee..4f4d95b 100644 --- a/src/client/auth/client.cpp +++ b/src/client/auth/client.cpp @@ -220,7 +220,7 @@ std::optional AuthClient::take_grant() { return std::exchange(impl_->grant, {}); } #ifndef _WIN32 -std::unique_ptr native_auth_platform() { +std::unique_ptr native_auth_platform(std::string_view) { return {}; } #endif diff --git a/src/client/auth/protocol.cpp b/src/client/auth/protocol.cpp index 22e3b2d..307bc1a 100644 --- a/src/client/auth/protocol.cpp +++ b/src/client/auth/protocol.cpp @@ -143,7 +143,22 @@ std::string auth_authorization_url(std::string_view state, std::string_view chal "&response_type=code&scope=openid%20email%20profile" + "&redirect_uri=" + auth_form_escape(auth_redirect) + "&code_challenge_method=S256" + "&code_challenge=" + auth_form_escape(challenge) + "&state=" + auth_form_escape(state) + - "&prompt=select_account"; + // The browser only opens when this profile has no usable saved login. Keycloak + // ignores select_account, so ask for the login form: the user picks the account + // instead of silently reusing the browser's single sign-on session. + "&prompt=login"; +} +bool auth_profile_valid(std::string_view profile) { + return profile.size() <= 32 && std::ranges::all_of(profile, [](char ch) { + return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || + (ch >= '0' && ch <= '9') || ch == '-' || ch == '_'; + }); +} +std::string auth_credential_name(std::string_view profile) { + std::string name{"AeternalisEvolution/DEV/refresh-token/v1"}; + if (!profile.empty()) + name += "/" + std::string{profile}; + return name; } std::expected auth_callback(std::string_view target, std::string_view state) { diff --git a/src/client/auth/windows.cpp b/src/client/auth/windows.cpp index 892f422..fa6b8e3 100644 --- a/src/client/auth/windows.cpp +++ b/src/client/auth/windows.cpp @@ -14,10 +14,11 @@ #include #include #include +#include +#include namespace evo::client { namespace { -constexpr wchar_t credential_name[] = L"AeternalisEvolution/DEV/refresh-token/v1"; struct InternetHandle { HINTERNET value{}; ~InternetHandle() { @@ -62,6 +63,7 @@ bool readable(SOCKET socket, long microseconds) { } class WindowsAuth final : public AuthPlatform { public: + explicit WindowsAuth(std::wstring credential) : credential_name_{std::move(credential)} {} std::expected authorize(std::stop_token stop) override { Winsock winsock; if (!winsock.ready) @@ -224,7 +226,7 @@ class WindowsAuth final : public AuthPlatform { } std::expected load_refresh() override { PCREDENTIALW credential = nullptr; - if (!CredReadW(credential_name, CRED_TYPE_GENERIC, 0, &credential)) { + if (!CredReadW(credential_name_.c_str(), CRED_TYPE_GENERIC, 0, &credential)) { if (GetLastError() == ERROR_NOT_FOUND) return std::string{}; return std::unexpected{AuthError::credential_store}; @@ -245,7 +247,7 @@ class WindowsAuth final : public AuthPlatform { return false; CREDENTIALW credential{}; credential.Type = CRED_TYPE_GENERIC; - credential.TargetName = const_cast(credential_name); + credential.TargetName = credential_name_.data(); credential.UserName = const_cast(L"aevolution-game"); credential.CredentialBlobSize = static_cast(token.size()); credential.CredentialBlob = reinterpret_cast(const_cast(token.data())); @@ -253,12 +255,17 @@ class WindowsAuth final : public AuthPlatform { return CredWriteW(&credential, 0) != 0; } bool erase_refresh() override { - return CredDeleteW(credential_name, CRED_TYPE_GENERIC, 0) != 0 || + return CredDeleteW(credential_name_.c_str(), CRED_TYPE_GENERIC, 0) != 0 || GetLastError() == ERROR_NOT_FOUND; } + + private: + std::wstring credential_name_; // One saved login per profile. }; } // namespace -std::unique_ptr native_auth_platform() { - return std::make_unique(); +std::unique_ptr native_auth_platform(std::string_view profile) { + if (!auth_profile_valid(profile)) + return {}; + return std::make_unique(wide(auth_credential_name(profile))); } } // namespace evo::client diff --git a/tests/client_auth.cpp b/tests/client_auth.cpp index 9b0d8ff..69d3ce1 100644 --- a/tests/client_auth.cpp +++ b/tests/client_auth.cpp @@ -94,10 +94,20 @@ void protocol_tests() { "https://auth.aeternalisgames.com/realms/aeternalis/protocol/openid-connect/auth?")); for (const std::string_view part : {"client_id=aevolution-game", "response_type=code", "code_challenge_method=S256", - "code_challenge=ch", "state=st", + "code_challenge=ch", "state=st", "prompt=login", "redirect_uri=http%3A%2F%2F127.0.0.1%3A47600%2Fcallback"}) CHECK(url.find(part) != std::string::npos); + // Profiles: one saved login each; the default keeps the original credential name. + CHECK(auth_profile_valid("") && auth_profile_valid("alt-2_B") && + auth_profile_valid(std::string(32, 'a'))); + for (const std::string_view bad : {"a b", "a/b", "..", "a\\b", "\xC3\xA9", "a:b"}) + CHECK(!auth_profile_valid(bad)); + CHECK(!auth_profile_valid(std::string(33, 'a'))); + CHECK(auth_credential_name("") == "AeternalisEvolution/DEV/refresh-token/v1"); + CHECK(auth_credential_name("second") == "AeternalisEvolution/DEV/refresh-token/v1/second"); + CHECK(!native_auth_platform("bad name")); + // Callback: exact path, the one state, one code; denial and anything else refused. CHECK(auth_callback("/callback?state=st&code=abc.DEF-1&session_state=x", "st") == "abc.DEF-1"); CHECK(auth_callback("/callback?code=c&state=st&iss=https%3A%2F%2Fauth.aeternalisgames.com%2F"