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
+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