Repository navigation
Add guest auth (T14) #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kirre-bylund
wants to merge
4
commits into
dev
Choose a base branch
from
t14-guest-auth
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,104 @@ | ||
| #pragma once | ||
|
|
||
| // Placeholder for the auth module's public surface. | ||
| // Guest authentication (D16, T14). | ||
| // | ||
| // T8 scaffolds the target graph only. The real surface lands with T14 (guest), T15 | ||
| // (white label), T16 (Steam) and T18 (end session + refresh), per | ||
| // specs-library/specs/discipline/sdk/cpp-sdk/api-sketch.md. | ||
| // A guest session is the MVP's primary auth path: no credentials, no platform, just an | ||
| // identifier the SDK generates once and reuses. **The reuse is the whole point** - a guest | ||
| // who loses their identifier silently becomes a new account with no inventory, so the SDK | ||
| // persists it (D8) and sends it back on the next launch. | ||
| // | ||
| // The identifier is generated here rather than by the caller, because a caller that has to | ||
| // invent one will invent a different one on the next launch. | ||
|
|
||
| #include <lootlocker/client.h> | ||
| #include <lootlocker/platform.h> | ||
| #include <lootlocker/request_id.h> | ||
| #include <lootlocker/result.h> | ||
| #include <lootlocker/session.h> | ||
|
|
||
| #include <functional> | ||
| #include <optional> | ||
| #include <string> | ||
|
|
||
| namespace lootlocker { | ||
|
|
||
| // The backend's `optionals` object, verbatim. | ||
| // | ||
| // **Named `optionals`, not `options`.** It is the backend's term for "a set of optional | ||
| // values", and `options` invokes a different meaning - configuration rather than | ||
| // per-request optional data. The other SDKs use the backend term for the same reason. | ||
| // | ||
| // Every field is optional, and the defaults are the backend's: an absent `timezone` means | ||
| // UTC, an absent `auto_create_profile` means true. | ||
| struct SessionOptionals { | ||
| // IANA format. Empty means "resolve it": the injected provider, then the OS, then | ||
| // `Etc/UTC` (D26). | ||
| std::string timezone; | ||
|
|
||
| // The player's display name. Empty means "leave it as it is". | ||
| std::string player_name; | ||
|
|
||
| // Whether to create a profile for a player who does not have one. Defaults to true; | ||
| // false makes the session fail with a 404 for an unknown player. | ||
| bool auto_create_profile = true; | ||
|
|
||
| // Whether the client reports owning DLC, so the server reconciles ownership at session | ||
| // start. Defaults to false. | ||
| bool check_dlc = false; | ||
|
|
||
| // The referrer's public UID, for attributing a referral on a first session. Ignored for | ||
| // returning players. | ||
| std::string referral_code; | ||
|
|
||
| // The referral program the code redeems. Omit when the game has a single active program. | ||
| std::string referral_program_key; | ||
| }; | ||
|
|
||
| // Everything a guest session start takes. | ||
| // | ||
| // **An input struct rather than parameters plus overloads** (owner, 2026-11-26). Two | ||
| // optional parameters is four overloads and four is sixteen; a struct is one shape that | ||
| // gains fields without breaking callers. The zero-argument `StartGuestSession(ll, cb)` stays | ||
| // as the common call. | ||
| // | ||
| // Both fields are `Optional` because neither is required, and "unset" is a different | ||
| // statement from "set to empty" - the same distinction `Config::send_timezone` exists to | ||
| // preserve. | ||
| struct GuestSessionInputs { | ||
| // The guest identifier to use. Unset means "use the persisted one, or generate a new | ||
| // one", which is what almost every caller wants. | ||
| // | ||
| // **Not part of `optionals`.** The backend's `optionals` object does not contain it, and | ||
| // muddling the two would make the SDK's shape disagree with the wire's. | ||
| std::optional<std::string> guest_identifier; | ||
|
|
||
| std::optional<SessionOptionals> optionals; | ||
| }; | ||
|
|
||
| using SessionCallback = std::function<void(Result<Session>)>; | ||
|
|
||
| namespace auth { | ||
|
|
||
| // Intentionally empty until T14. The header exists so the target graph and the | ||
| // include-path boundary (D18) can be verified before any feature is written. | ||
| // POST /game/v2/session/guest | ||
| // | ||
| // Starts a guest session and stores it on the client, so subsequent requests carry | ||
| // `x-session-token` and `Client::GetSession()` returns it. | ||
| // | ||
| // **The identifier is resolved in this order:** `inputs.guest_identifier` if set, then the | ||
| // one persisted by a previous session, then a newly generated one. Whatever is chosen is | ||
| // persisted before the request is sent, so a crash between sending and receiving does not | ||
| // lose it and orphan the account. | ||
| // | ||
| // **The session token is never sent on this request.** An authentication request is not an | ||
| // authenticated request, so attaching a token to it is wrong by definition - and a stale | ||
| // token from a previous session would be sent to an endpoint that has no use for it. | ||
| // | ||
| // Returns the id the executor assigned. The callback fires on the thread that calls | ||
| // `Client::Update()` (D5). | ||
| RequestId StartGuestSession(Client& ll, SessionCallback on_done); | ||
|
|
||
| RequestId StartGuestSession(Client& ll, const GuestSessionInputs& inputs, | ||
| SessionCallback on_done); | ||
|
|
||
| } // namespace auth | ||
| } // namespace lootlocker |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #pragma once | ||
|
|
||
| // The auth platform (D16, T14 review). | ||
| // | ||
| // A wire value, not a free string. The API accepts a fixed set of platform names and rejects | ||
| // anything else, so a typo in a string literal is a runtime 400 that a type would have caught | ||
| // at compile time. The names match the other SDKs' `LL_AuthPlatforms` exactly, because the | ||
| // backend compares them literally. | ||
|
|
||
| #include <lootlocker/json_value.h> | ||
| #include <lootlocker/result.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace lootlocker { | ||
|
|
||
| enum class Platform { | ||
| None = 0, | ||
| Guest, | ||
| WhiteLabel, | ||
| Steam, | ||
| PlayStationNetwork, | ||
| XboxOne, | ||
| NintendoSwitch, | ||
| AmazonLuna, | ||
| AppleSignIn, | ||
| AppleGameCenter, | ||
| Android, | ||
| GoogleSignIn, | ||
| GooglePlayGames, | ||
| EpicGames, | ||
| Meta, | ||
| Remote, | ||
| Discord, | ||
| }; | ||
|
|
||
| // The wire name, e.g. `"guest"`. Never null. | ||
| const char* ToString(Platform platform); | ||
|
|
||
| // Parses a wire name. Returns false and leaves `out` untouched when the name is unknown, | ||
| // rather than defaulting to `None` - an unknown platform is a contract change, not a | ||
| // missing value. | ||
| bool TryParsePlatform(const std::string& name, Platform& out); | ||
|
|
||
| // The ADL deserialiser, so a platform round-trips through the JSON layer like any other | ||
| // field (D27). There is no `to_json`: a `JsonBuilder` writes into an object, so a bare enum | ||
| // has no key to write under. A caller serialises with `b.Set("platform", ToString(p))`. | ||
| Result<Empty> from_json(const JsonValue& j, Platform& out); | ||
|
|
||
| } // namespace lootlocker |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #pragma once | ||
|
|
||
| // The session (D8, D12). A wire mirror: fields are `snake_case` and match the JSON exactly. | ||
| // | ||
| // This is the one type that is both a wire mirror and a persisted record, which is why its | ||
| // field set is exactly what D8 says to store and nothing more. | ||
|
|
||
| #include <lootlocker/json_value.h> | ||
| #include <lootlocker/result.h> | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <type_traits> | ||
|
|
||
| namespace lootlocker { | ||
|
|
||
| struct Session { | ||
| std::string session_token; | ||
| std::string player_identifier; | ||
| std::string player_ulid; | ||
| std::string public_uid; | ||
| std::string player_name; | ||
| std::uint64_t player_id = 0; // uint64 on the wire; see D4 | ||
| std::string player_created_at; | ||
| bool seen_before = false; | ||
| bool check_grant_notifications = false; | ||
| bool check_deactivation_notifications = false; | ||
| }; | ||
|
|
||
| // `player_id` must stay an unsigned 64-bit integer. | ||
| // | ||
| // **This is R9's documented mitigation, not a guard against someone editing the struct.** | ||
| // The D4 spike showed both candidate parsers are exact by default, so the hazard is not the | ||
| // parser but a `double` field in our own structs - and the failure is silent, because a | ||
| // value above 2^53 loses precision without any error. The assert is what makes adding such | ||
| // a field a compile error rather than a support ticket. | ||
| static_assert(sizeof(Session::player_id) == 8 && !std::is_floating_point<decltype(Session::player_id)>::value, | ||
| "player_id must be an unsigned 64-bit integer (D4, R9)"); | ||
|
|
||
| // Decodes a session response (D27). | ||
| // | ||
| // **Which fields are required, and why that is not a silent default.** D23 says a missing | ||
| // field is a decode error rather than a zero, and that rule exists to stop a field the SDK | ||
| // depends on being silently defaulted. It does not mean every field is mandatory: | ||
| // | ||
| // - `session_token`, `player_identifier`, `player_ulid`, `public_uid` and `player_id` are | ||
| // required. Without them the session is unusable or the player cannot be identified, | ||
| // and a default would be a lie. | ||
| // - `player_name` is optional, because an absent name genuinely means "this player has | ||
| // not set one". Defaulting it to empty is the correct reading, not a silent default. | ||
| // - `player_created_at` and the three booleans are optional for the same reason: they are | ||
| // display and notification hints, and the API omits them on some auth paths. | ||
| Result<Empty> from_json(const JsonValue& j, Session& out); | ||
|
|
||
| } // namespace lootlocker | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.