ADR-0131: per-profile client sign-in for several clients on one machine
Foundation / checks (ecs) (push) Successful in 2m21s
Foundation / checks (deploy) (push) Successful in 4m9s
Foundation / checks (tsan) (push) Successful in 9m48s
Foundation / checks (client) (push) Successful in 19m17s
Foundation / checks (network) (push) Successful in 19m44s
Foundation / checks (checks) (push) Successful in 42m37s
Foundation / checks (postgres) (push) Successful in 45m40s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 3m13s
Foundation / image (push) Successful in 3m27s

Only one client per machine could sign in: the saved login lived under a single
Credential Manager name, and Keycloak ignores prompt=select_account, so the
browser reused its single sign-on session. --profile NAME keeps one saved login
per profile (the default name is unchanged), and authorization asks for
prompt=login so the browser shows the login form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-15 17:35:53 -04:00
co-authored by Claude Opus 5.5
parent 898c921da8
commit a97f0c3fea
10 changed files with 79 additions and 16 deletions
+8 -3
View File
@@ -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;
@@ -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.
@@ -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 `/<profile>` 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,
+4 -1
View File
@@ -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)".
+14
View File
@@ -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/<NAME>`. 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.
+7 -1
View File
@@ -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<AuthPlatform> 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<AuthPlatform> native_auth_platform(std::string_view profile = {});
[[nodiscard]] std::string auth_form_escape(std::string_view value);
[[nodiscard]] std::string auth_base64url(std::span<const std::uint8_t> bytes);
+1 -1
View File
@@ -220,7 +220,7 @@ std::optional<AuthGrant> AuthClient::take_grant() {
return std::exchange(impl_->grant, {});
}
#ifndef _WIN32
std::unique_ptr<AuthPlatform> native_auth_platform() {
std::unique_ptr<AuthPlatform> native_auth_platform(std::string_view) {
return {};
}
#endif
+16 -1
View File
@@ -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<std::string, AuthError> auth_callback(std::string_view target,
std::string_view state) {
+13 -6
View File
@@ -14,10 +14,11 @@
#include <array>
#include <cctype>
#include <limits>
#include <string>
#include <utility>
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<AuthorizationCode, AuthError> authorize(std::stop_token stop) override {
Winsock winsock;
if (!winsock.ready)
@@ -224,7 +226,7 @@ class WindowsAuth final : public AuthPlatform {
}
std::expected<std::string, AuthError> 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<wchar_t*>(credential_name);
credential.TargetName = credential_name_.data();
credential.UserName = const_cast<wchar_t*>(L"aevolution-game");
credential.CredentialBlobSize = static_cast<DWORD>(token.size());
credential.CredentialBlob = reinterpret_cast<LPBYTE>(const_cast<char*>(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<AuthPlatform> native_auth_platform() {
return std::make_unique<WindowsAuth>();
std::unique_ptr<AuthPlatform> native_auth_platform(std::string_view profile) {
if (!auth_profile_valid(profile))
return {};
return std::make_unique<WindowsAuth>(wide(auth_credential_name(profile)));
}
} // namespace evo::client
+11 -1
View File
@@ -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"