ADR-0131: Keycloak sign-in in the Windows engineering client
Foundation / checks (ecs) (push) Successful in 2m21s
Foundation / checks (deploy) (push) Successful in 4m1s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 7m21s
Foundation / checks (network) (push) Canceled after 9m43s
Foundation / checks (checks) (push) Canceled after 9m49s
Foundation / checks (postgres) (push) Canceled after 9m43s
Foundation / checks (client) (push) Canceled after 9m48s
Foundation / checks (ecs) (push) Successful in 2m21s
Foundation / checks (deploy) (push) Successful in 4m1s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 7m21s
Foundation / checks (network) (push) Canceled after 9m43s
Foundation / checks (checks) (push) Canceled after 9m49s
Foundation / checks (postgres) (push) Canceled after 9m43s
Foundation / checks (client) (push) Canceled after 9m48s
Sign In / Register opens the system browser (PKCE S256, loopback 127.0.0.1:47600) and keeps the refresh token in Windows Credential Manager. The client then fetches a 10-minute grant from grants.aeternalisgames.com and connects to the cellular DEV region. It renews the grant about a minute before expiry through SessionRefresh, and again after a lost connection. Sign Out closes the session and revokes the login at the broker and at Keycloak. Grant replies are cross-checked against the grant record before use. The manual grant-bundle path stays for developers. The bounded JSON reader moves to evo_json (evo::serialization), shared by the broker and the client. Adds the client-auth tests. Completes work started in another session: main.cpp wiring, refresh expiry tracking, no requests for a superseded session, and clang-tidy and Windows header-order fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "cellular_scene.hpp"
|
||||
#include "controls_flow.hpp"
|
||||
#include "evo/client/application.hpp"
|
||||
#include "evo/client/auth.hpp"
|
||||
#include "evo/client/launcher.hpp"
|
||||
#include "evo/client/selection.hpp"
|
||||
#include "evo/client/session_host.hpp"
|
||||
@@ -19,6 +20,7 @@
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
@@ -229,6 +231,12 @@ std::uint64_t milliseconds(std::chrono::steady_clock::time_point t) {
|
||||
return static_cast<std::uint64_t>(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(t.time_since_epoch()).count());
|
||||
}
|
||||
// Wall-clock seconds: grant expiry is UTC (the session compares the server's welcome).
|
||||
std::uint64_t utc_seconds() {
|
||||
return static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) try {
|
||||
@@ -351,6 +359,36 @@ int main(int argc, char** argv) try {
|
||||
return host.connect(std::move(opened));
|
||||
}
|
||||
};
|
||||
// ADR-0131: a broker grant names its region route; only the region CA comes from the
|
||||
// form. The grant stays in memory and the session asks for the next one itself.
|
||||
const auto grant_material = [&](const evo::client::AuthGrant& grant) {
|
||||
auto f = buffers.form();
|
||||
f.endpoint = grant.endpoint;
|
||||
f.server_name = grant.server_name;
|
||||
return evo::client::load_connect(f, std::span{&grant.bytes, 1});
|
||||
};
|
||||
const auto connect_signed_in = [&](const evo::client::AuthGrant& grant) {
|
||||
form_error.reset();
|
||||
if constexpr (!evo::client_app::remote_available) {
|
||||
form_error = evo::client::LaunchError::no_session;
|
||||
return false;
|
||||
} else {
|
||||
const auto material = grant_material(grant);
|
||||
if (!material) {
|
||||
form_error = material.error();
|
||||
return false;
|
||||
}
|
||||
cellular_trial = true; // The DEV broker world is the cellular trial (ADR-0131).
|
||||
auto opened = evo::client_app::RemoteSession::open(*material, cellular_trial);
|
||||
if (!opened) {
|
||||
form_error = evo::client::LaunchError::endpoint;
|
||||
return false;
|
||||
}
|
||||
opened->manage_grants();
|
||||
cellular_framed = false;
|
||||
return host.connect(std::move(opened));
|
||||
}
|
||||
};
|
||||
const auto enter_fixture = [&] {
|
||||
if (!authority) {
|
||||
authority = make_authority();
|
||||
@@ -419,6 +457,10 @@ int main(int argc, char** argv) try {
|
||||
return &remote->organisms();
|
||||
return nullptr;
|
||||
};
|
||||
// ADR-0131 browser sign-in (Windows); elsewhere the panel offers manual grants only.
|
||||
evo::client::AuthClient auth{evo::client::native_auth_platform()};
|
||||
bool auth_connect = false; // Connect when the requested grant arrives.
|
||||
auto grant_requested = std::chrono::steady_clock::time_point{};
|
||||
int drawn_organisms = -1;
|
||||
evo::client_app::PanelActions actions;
|
||||
(*app)->set_overlay([&] {
|
||||
@@ -428,6 +470,7 @@ int main(int argc, char** argv) try {
|
||||
view.form_error = form_error;
|
||||
view.remote_available = evo::client_app::remote_available;
|
||||
view.cellular_trial = cellular_trial;
|
||||
view.auth = auth.status();
|
||||
view.environment = shown_environment();
|
||||
view.organisms = shown_organisms();
|
||||
view.selection = &selection;
|
||||
@@ -512,6 +555,48 @@ int main(int argc, char** argv) try {
|
||||
remote->set_cellular_feed_target(cellular_trial ? cellular_feed_target : std::nullopt);
|
||||
remote->set_cellular_controls(buffers.cellular_controls);
|
||||
}
|
||||
// ADR-0131 sign-in. One request at a time; grants arrive on a later frame.
|
||||
if (actions.sign_in && auth.sign_in()) {
|
||||
auth_connect = true;
|
||||
grant_requested = now;
|
||||
}
|
||||
if (actions.auth_connect && auth.request_grant()) {
|
||||
auth_connect = true;
|
||||
grant_requested = now;
|
||||
}
|
||||
if (actions.cancel_sign_in) {
|
||||
auth.cancel();
|
||||
auth_connect = false;
|
||||
}
|
||||
if (actions.sign_out) {
|
||||
host.cancel(); // Logout revokes every grant; do not keep a session behind it.
|
||||
cellular_feed_target.reset();
|
||||
selection.clear();
|
||||
auth_connect = false;
|
||||
static_cast<void>(auth.sign_out());
|
||||
}
|
||||
if (auto grant = auth.take_grant()) {
|
||||
if (auth_connect) {
|
||||
auth_connect = false;
|
||||
if (connect_signed_in(*grant))
|
||||
selection.clear();
|
||||
} else if (auto* remote = host.session()) {
|
||||
// Refresh or reconnect material for the live session (same account).
|
||||
if (const auto material = grant_material(*grant))
|
||||
static_cast<void>(remote->supply_grant(*material));
|
||||
}
|
||||
grant->bytes.fill(0);
|
||||
}
|
||||
if (const auto status = auth.status(); !status.busy && auth_connect && !status.signed_in)
|
||||
auth_connect = false; // Sign-in failed or was cancelled; the panel shows why.
|
||||
// About a minute before expiry, or after a lost connection; never for a session the
|
||||
// launcher has given up on (superseded by another client, cancelled).
|
||||
const bool live = launcher.phase() == evo::client::LaunchPhase::connecting ||
|
||||
launcher.phase() == evo::client::LaunchPhase::connected;
|
||||
if (const auto* remote = host.session();
|
||||
live && remote && remote->needs_grant(utc_seconds()) &&
|
||||
now - grant_requested >= std::chrono::seconds{5} && auth.request_grant())
|
||||
grant_requested = now;
|
||||
controls.step(actions, **app, ui);
|
||||
actions = {};
|
||||
// The launcher and modal dialogs own input: no world movement or selection.
|
||||
|
||||
Reference in New Issue
Block a user