Repository navigation
Add guest auth (T14) - #14
Open
kirre-bylund wants to merge 4 commits into
Open
kirre-bylund wants to merge 4 commits into
kirre-bylund wants to merge 4 commits into
Conversation
POST /game/v2/session/guest, with the player_identifier reuse that is the whole point of guest auth: a guest who loses their identifier silently becomes a new account with no inventory. The identifier is resolved as caller-supplied, then persisted, then generated, and the resolved value is written BEFORE the request is sent. A crash between sending and receiving would otherwise orphan the account the server just created. A successful session is stored on the client, so subsequent requests carry x-session-token. The token is read at send time rather than at queue time, so a request queued before a session started still carries the token once it is sent. Session decoding distinguishes required from optional fields. D23 says a missing field is an error rather than a zero, but that rule is about fields the SDK depends on: session_token, player_identifier, player_ulid, public_uid and player_id are required, while player_name and the notification hints are genuinely optional and an absent name means "not set". player_id is read through IsUnsigned/AsUInt64 so a value above 2^53 survives. Two test bugs found and fixed, both the same mistake: - The reuse test assigned a temporary shared_ptr to Config::state_writer, which expires before the Client is constructed, so both clients fell back to the default file and the test passed for the wrong reason. - A stale lootlocker-state.txt in the working directory then masked a sabotage, so the test appeared to pass with persistence removed. Tests now hold named writers, and the ones that do not care about persistence inject a NullStateWriter so they cannot touch the shared default file. Verified by sabotage: removing the persist call now fails the reuse test with two different identifiers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Approval is blocked by active correctness issues in guest-session request shaping, timezone and identifier persistence, empty-response validation, and malformed-field diagnostics.
5 open issues
What changed in this PR
Adds T14 guest authentication to the C++ SDK, including guest session requests, response decoding, identifier persistence, client session state, and automated coverage.
Changes:
- Adds the public
Sessionmodel, guest-auth options, andauth::StartGuestSessionAPI. - Integrates identifier resolution, session-token propagation, and client session accessors.
- Updates build integration, documentation, and authentication tests.
| File | Description |
|---|---|
| tests/test_auth.cpp | Adds guest-auth request, decoding, persistence, token propagation, and accessor tests. |
| tests/CMakeLists.txt | Registers the authentication test target when the auth module is available. |
| src/core/session.cpp | Implements strict decoding and validation of session response fields. |
| src/core/optional.h | Adds the internal optional-value type alias. |
| src/core/executor.h | Adds executor configuration for retrieving the current session token. |
| src/core/executor.cpp | Injects the current session token when requests are dispatched. |
| src/core/client.cpp | Stores client session state and wires session-token lookup into the executor. |
| src/auth/auth.cpp | Implements guest-session request construction, identifier resolution, persistence, and session storage. |
| README.md | Documents guest authentication, identifier reuse, and session access. |
| include/lootlocker/session.h | Defines the public session model and decoder contract. |
| include/lootlocker/client.h | Exposes client session accessors and mutators. |
| include/lootlocker/auth.h | Defines guest-session options and public authentication entry points. |
| CMakeLists.txt | Adds session support to the core build and exposes internal headers to feature modules. |
Review effort: Lite
The serious one: the request body was wrong. The backend's GuestInput embeds BaseInput and carries Optionals tagged json:"optionals", so timezone, locale, player_name and character_name at the root were silently ignored and every player got UTC. Verified against services/gamesession/models.go rather than inferred from the Unity SDK. The optionals are now a nested object, omitted entirely when empty. A 200 with an empty body became an all-default Session, so HasSession() reported true with no token. The generic Send treats an empty body as success because a 204 is the one legitimate empty success, which is wrong for a definition whose response carries required fields. Such a definition now opts out with kAllowEmptyResponse = false. The timezone was never resolved: an empty option sent nothing and Config::timezone, Config::timezone_provider and Config::send_timezone were all ignored. Now resolved in the documented order and normalised to an IANA name, because a Windows name sent as-is gets UTC server-side. An explicit player_identifier was not persisted, so a game that supplied one on the first launch and relied on the SDK afterwards got a different account on the next launch - the exact failure the mechanism exists to prevent. A present field of the wrong type reported "missing", which sends the reader looking in the wrong place. Wrong-type and missing are now distinct messages. Verified by sabotage: allowing an empty response fails two assertions, and flattening the optionals back to the root fails four. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
kirre-bylund
commented
Nov 26, 2026
kirre-bylund
left a comment
Contributor
Author
There was a problem hiding this comment.
Major changes needed
Twelve findings, several of them design changes. The optionals were wrong. locale and character_name were invented - the backend's optionals are timezone, player_name, auto_create_profile, check_dlc, referral_code and referral_program_key. A field equal to the backend's default is now omitted rather than sent. GuestSessionOptions is now GuestSessionInputs, holding an Optional guest_identifier and an Optional SessionOptionals. The identifier is not part of optionals on the wire, so putting it there made the SDK's shape disagree with the backend's. The input struct is the general pattern for every SDK method from here. The session token is no longer sent on authentication requests. An authentication request is not an authenticated request by definition, and a stale token from a previous session has no business being sent to it. A definition opts out with kRequiresSession = false. The persisted key is guest_identifier, not player_identifier: the wire field is player_identifier on every platform, but only on guest is it a client-generated value. Platform is now an enum with wire names matching the other SDKs, so a typo is a compile error rather than a runtime 400. The JSON field readers moved into the core JSON layer. Every decoder needs the same three questions answered, and writing them per type is how two decoders end up disagreeing about whether a null counts as absent. The static_asserts on Session are gone - they guarded against someone changing a type, which is not a thing that happens. DefinitionTraits replaces them with asserts that name what a definition is missing, which is the real benefit an interface would have offered without the vtable. Also: make_unique in the tests, and a note that multi-session is deliberately deferred. Verified by sabotage: always sending the token fails the auth-request test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Approval is blocked by active correctness issues, including a guest-auth path that accepts malformed 204 responses and bypasses the system timezone provider, plus missing compile-time safeguards.
4 open issues
5 resolved since last review
Review effort: Lite
The high-severity one: kAllowEmptyResponse did not protect the 204 path. The condition accepted every 204 before checking the flag, so a 204 from an endpoint whose response carries required fields still became an all-default Session and HasSession() reported true. Both the 204 and the empty-body case are now gated on the flag, via if constexpr so the branch is genuinely compiled out. The timezone resolver skipped the OS step. I had reimplemented the chain locally and left out SystemTimezoneProvider, so a normal guest start ignored the machine timezone entirely. It now delegates to the public ResolveTimezone helper that already existed - which is the real lesson: the helper was there and I wrote a second one. DefinitionTraits was dead code: the static_asserts were never instantiated, so a definition missing kMethod still failed later in an unrelated template expression. Send now instantiates it. The player_id static_assert is restored. The owner asked me to remove it as guarding against a type change nobody makes, but R9 names it as the documented mitigation for the silent 2^53 truncation, so removing it would have left the spec claiming a guard that no longer existed. Flagged on the PR for the owner to overrule if they still disagree. Verified by sabotage: ungating the 204 fails four assertions, and skipping the OS step fails four more. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Implements T14 from
specs-library/specs/discipline/sdk/cpp-sdk/tasks.md.What this adds
include/lootlocker/session.h— theSessionstruct and its decoder.include/lootlocker/auth.h—GuestSessionOptionsandauth::StartGuestSession.src/auth/auth.cpp— the guest session definition, identifier resolution and persistence.Client::HasSession/GetSession/SetSession/ClearSession.tests/test_auth.cpp— 12 test functions.Verification
The task's stated check:
auth::StartGuestSessionoverPOST /game/v2/session/guest, includingplayer_identifierreuse across restarts.TestPlayerIdentifierIsReusedAcrossRestartssimulates a restart by constructing a second client against the same file and asserts the identifier is identical.16/16 CTest targets pass with curl, 14/14 in the
-DLOOTLOCKER_MODULE_ONLY=coreconfiguration. Include boundary clean.The identifier reuse
This is the whole point of guest auth: a guest who loses their
player_identifiersilently becomes a new account with no inventory. Resolution order is caller-supplied, then persisted, then generated — and the resolved value is written before the request is sent, so a crash between sending and receiving does not orphan the account the server just created.Required vs optional fields
D23 says a missing field is a decode error rather than a zero. That rule is about fields the SDK depends on, not about every field:
session_token,player_identifier,player_ulid,public_uid,player_id. Without them the session is unusable or the player cannot be identified.player_name,player_created_atand the three notification booleans. An absent name genuinely means "this player has not set one", and the API omits the rest on some auth paths.player_idis read throughIsUnsigned()/AsUInt64()so a value above 2^53 survives — the D4 hazard.The token is read at send time, not queue time
ExecutorSettingsgained asession_tokencallback rather than a string. A request queued before a session started still carries the token once it is actually sent, which is what a caller expects.Two test bugs, both the same mistake
The reuse test passed for the wrong reason. It assigned a temporary
shared_ptrtoConfig::state_writer, which expires before theClientis constructed — so both clients fell back to the default file and the test proved nothing. This is the exact mistake the README warns about, and I made it in the test.A stale
lootlocker-state.txtthen masked a sabotage. With the file present in the working directory, removing the persist call still passed, because the default writer had a leftover identifier. Tests now hold named writers, and the ones that do not care about persistence inject aNullStateWriterso they cannot touch the shared default file.Verified by sabotage: removing the persist call now fails the reuse test with two different identifiers.
Note on scope
T12b(the session/player state object) is still open. This PR persists the identifier, which is what guest continuity needs; T12b adds the rest of the identity and the session token to the store.