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:
@@ -0,0 +1,109 @@
|
||||
#pragma once
|
||||
#include "evo/client/launcher.hpp"
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <stop_token>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace evo::client {
|
||||
inline constexpr std::string_view auth_redirect = "http://127.0.0.1:47600/callback";
|
||||
inline constexpr std::string_view auth_client_id = "aevolution-game";
|
||||
enum class AuthError : std::uint8_t {
|
||||
unavailable,
|
||||
cancelled,
|
||||
listener,
|
||||
timeout,
|
||||
browser,
|
||||
transport,
|
||||
invalid_response,
|
||||
denied,
|
||||
token_expired,
|
||||
email_unverified,
|
||||
throttled,
|
||||
service_unavailable,
|
||||
credential_store,
|
||||
logout_incomplete
|
||||
};
|
||||
[[nodiscard]] std::string_view auth_error_text(AuthError error);
|
||||
struct AuthGrant {
|
||||
GrantRecord bytes{};
|
||||
std::string account, endpoint, server_name;
|
||||
std::uint64_t region{}, expires_at{};
|
||||
};
|
||||
struct AuthTokens {
|
||||
std::string access, refresh;
|
||||
std::uint64_t lifetime{};
|
||||
};
|
||||
struct AuthorizationCode {
|
||||
std::string code, verifier;
|
||||
};
|
||||
struct AuthHttpReply {
|
||||
unsigned status{};
|
||||
std::string body;
|
||||
};
|
||||
enum class AuthEndpoint : std::uint8_t { token, grant, logout, revoke };
|
||||
// Opaque tokens stay inside the worker/platform boundary. No UI, logs or plaintext files.
|
||||
class AuthPlatform {
|
||||
public:
|
||||
virtual ~AuthPlatform() = default;
|
||||
[[nodiscard]] virtual std::expected<AuthorizationCode, AuthError>
|
||||
authorize(std::stop_token stop) = 0;
|
||||
[[nodiscard]] virtual std::expected<AuthHttpReply, AuthError> post(AuthEndpoint endpoint,
|
||||
std::string_view body,
|
||||
std::string_view bearer,
|
||||
std::stop_token stop) = 0;
|
||||
[[nodiscard]] virtual std::expected<std::string, AuthError> load_refresh() = 0;
|
||||
[[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.
|
||||
|
||||
[[nodiscard]] std::string auth_form_escape(std::string_view value);
|
||||
[[nodiscard]] std::string auth_base64url(std::span<const std::uint8_t> bytes);
|
||||
[[nodiscard]] std::string auth_authorization_url(std::string_view state,
|
||||
std::string_view challenge);
|
||||
// Only the exact loopback path, one matching state, and one code (or denial) are accepted.
|
||||
[[nodiscard]] std::expected<std::string, AuthError> auth_callback(std::string_view target,
|
||||
std::string_view state);
|
||||
[[nodiscard]] std::expected<AuthTokens, AuthError> auth_tokens(const AuthHttpReply& reply);
|
||||
[[nodiscard]] std::expected<AuthGrant, AuthError> auth_grant(const AuthHttpReply& reply,
|
||||
std::uint64_t now_seconds);
|
||||
|
||||
enum class AuthPhase : std::uint8_t {
|
||||
signed_out,
|
||||
signing_in,
|
||||
ready,
|
||||
renewing,
|
||||
signing_out,
|
||||
failed
|
||||
};
|
||||
struct AuthStatus {
|
||||
AuthPhase phase{AuthPhase::signed_out};
|
||||
bool supported{}, busy{}, signed_in{};
|
||||
std::optional<AuthError> error;
|
||||
};
|
||||
// One joined worker, serialized refresh-token rotation; main-thread caller only.
|
||||
// Destruction cancels browser waiting and joins bounded network work.
|
||||
class AuthClient {
|
||||
public:
|
||||
explicit AuthClient(std::unique_ptr<AuthPlatform> platform);
|
||||
~AuthClient();
|
||||
AuthClient(const AuthClient&) = delete;
|
||||
AuthClient& operator=(const AuthClient&) = delete;
|
||||
[[nodiscard]] bool sign_in();
|
||||
[[nodiscard]] bool request_grant();
|
||||
[[nodiscard]] bool sign_out();
|
||||
void cancel();
|
||||
[[nodiscard]] AuthStatus status() const;
|
||||
[[nodiscard]] std::optional<AuthGrant> take_grant();
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
} // namespace evo::client
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
@@ -54,6 +55,9 @@ struct ConnectMaterial {
|
||||
// "host:port", "[ipv6]:port" or "a.b.c.d:port"; plain DNS host names only.
|
||||
[[nodiscard]] std::expected<Endpoint, LaunchError> parse_endpoint(std::string_view text);
|
||||
[[nodiscard]] std::expected<ConnectMaterial, LaunchError> load_connect(const ConnectForm& form);
|
||||
// Broker grants stay in memory; the existing pinned region CA is still required.
|
||||
[[nodiscard]] std::expected<ConnectMaterial, LaunchError>
|
||||
load_connect(const ConnectForm& form, std::span<const GrantRecord> grants);
|
||||
|
||||
// What the session reports while connecting, reduced to what the launcher decides on.
|
||||
enum class ConnectSignal : std::uint8_t {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// ADR-0131: a small, bounded JSON reader for access-token claims and the realm's JWKS.
|
||||
// It accepts RFC 8259 JSON within the bounds below and nothing else (no comments, no
|
||||
// trailing commas, no duplicate-key resolution beyond "first wins").
|
||||
namespace evo::serialization {
|
||||
inline constexpr std::size_t max_json_bytes = std::size_t{16} * 1024;
|
||||
inline constexpr std::size_t max_json_depth = 16;
|
||||
|
||||
class JsonValue {
|
||||
public:
|
||||
enum class Kind : std::uint8_t { null, boolean, number, string, array, object };
|
||||
[[nodiscard]] Kind kind() const noexcept {
|
||||
return kind_;
|
||||
}
|
||||
// Typed views; nullopt or nullptr when the value has another kind.
|
||||
[[nodiscard]] std::optional<bool> boolean() const;
|
||||
[[nodiscard]] std::optional<std::string_view> string() const;
|
||||
// Integers only (no fraction or exponent), within 0..2^63-1.
|
||||
[[nodiscard]] std::optional<std::uint64_t> integer() const;
|
||||
[[nodiscard]] const JsonValue* member(std::string_view name) const;
|
||||
[[nodiscard]] const std::vector<JsonValue>* array() const;
|
||||
|
||||
// Whole-document parse; nullopt for anything malformed or out of bounds.
|
||||
[[nodiscard]] static std::optional<JsonValue> parse(std::string_view text);
|
||||
|
||||
private:
|
||||
friend class JsonParser;
|
||||
Kind kind_{Kind::null};
|
||||
bool boolean_{};
|
||||
std::string text_; // String value, or the number's literal.
|
||||
std::vector<JsonValue> items_;
|
||||
std::vector<std::pair<std::string, JsonValue>> members_;
|
||||
};
|
||||
} // namespace evo::serialization
|
||||
@@ -1,44 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// ADR-0131: a small, bounded JSON reader for access-token claims and the realm's JWKS.
|
||||
// It accepts RFC 8259 JSON within the bounds below and nothing else (no comments, no
|
||||
// trailing commas, no duplicate-key resolution beyond "first wins").
|
||||
#include "evo/serialization/json.hpp"
|
||||
// Compatibility names for the broker; the parser has no server or persistence dependency.
|
||||
namespace evo::server::broker {
|
||||
inline constexpr std::size_t max_json_bytes = std::size_t{16} * 1024;
|
||||
inline constexpr std::size_t max_json_depth = 16;
|
||||
|
||||
class JsonValue {
|
||||
public:
|
||||
enum class Kind : std::uint8_t { null, boolean, number, string, array, object };
|
||||
[[nodiscard]] Kind kind() const noexcept {
|
||||
return kind_;
|
||||
}
|
||||
// Typed views; nullopt or nullptr when the value has another kind.
|
||||
[[nodiscard]] std::optional<bool> boolean() const;
|
||||
[[nodiscard]] std::optional<std::string_view> string() const;
|
||||
// Integers only (no fraction or exponent), within 0..2^63-1.
|
||||
[[nodiscard]] std::optional<std::uint64_t> integer() const;
|
||||
[[nodiscard]] const JsonValue* member(std::string_view name) const;
|
||||
[[nodiscard]] const std::vector<JsonValue>* array() const;
|
||||
|
||||
// Whole-document parse; nullopt for anything malformed or out of bounds.
|
||||
[[nodiscard]] static std::optional<JsonValue> parse(std::string_view text);
|
||||
|
||||
private:
|
||||
friend class JsonParser;
|
||||
Kind kind_{Kind::null};
|
||||
bool boolean_{};
|
||||
std::string text_; // String value, or the number's literal.
|
||||
std::vector<JsonValue> items_;
|
||||
std::vector<std::pair<std::string, JsonValue>> members_;
|
||||
};
|
||||
using serialization::JsonValue;
|
||||
using serialization::max_json_bytes;
|
||||
using serialization::max_json_depth;
|
||||
} // namespace evo::server::broker
|
||||
|
||||
Reference in New Issue
Block a user