Repository navigation
feat(social): P2-1c legacy social providers migrate onto the registry - #352
Conversation
Config becomes the FIRST-BOOT seed only (INSERT-only: admin edits to the google/wechat/github rows win and survive restarts); after that the row is the runtime source of truth -- credential rotation, enable/disable take effect on the next refresh (60s loop or any registry mutation) WITHOUT a restart: - Google/WeChat/GitHub services gain setCredentials (hot swap) - SocialLoginGuard: static entries become runtime-mutable (updateStaticProvider; enabled row may ENABLE a provider config never configured, redirect per the shared callback convention; disabled row removes the key -> authorize/validate 404); providers_ access locked - authorize URLs built from CURRENT row credentials via the new buildSocialAuthorizeUrlWithCredentials (byte-identical shapes; the config-based builder delegates to it) - UpstreamProviderRuntime: refresh over listAll (legacy rows need the disabled state too), legacy rows skipped from endpoint resolution and the dynamic set, new LegacyApplier seam (weak-ref to runtime, guard re-targeted via setGuardTarget + legacyState_ replay) - AuthProvidersController: runtime per-key enable/disable keeps the login-page listing in lockstep (never advertises a 404ing provider) - integration test: SQL-seeded github row drives the static surface (listing, authorize URL with row creds, admin PUT disable -> 404, admin CREATE still rejects reserved keys) - api-diff baseline ratified (--force: additive members to public classes; v1.x promises source-level SemVer only)
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf657f3ebb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (key == "google") | ||
| googleAuthService->setCredentials(clientId, clientSecret); | ||
| else if (key == "wechat") | ||
| weChatAuthService->setCredentials(clientId, clientSecret); | ||
| else if (key == "github") | ||
| gitHubAuthService->setCredentials(clientId, clientSecret); |
There was a problem hiding this comment.
Update login-service wiring when enabling a legacy provider
When a provider was unconfigured or tier-disabled at startup, its login controller receives a null service pointer, and SocialLinkService likewise receives null for that provider. This applier updates credentials, the guard, and discovery, but never replaces those null pointers. Consequently, enabling the registry row advertises a working authorize URL while the callback still uses the config-based fallback in GoogleController, WeChatController, or GitHubController, which rejects the original missing credentials or uses stale ones; linking also remains unavailable. Update the effective service wiring along with the registry state so DB-driven enablement works through the actual code exchange, not just discovery and authorization.
Useful? React with 👍 / 👎.
| void setCredentials(std::string clientId, std::string clientSecret) | ||
| { | ||
| clientId_ = std::move(clientId); | ||
| clientSecret_ = std::move(clientSecret); |
There was a problem hiding this comment.
Synchronize credential updates with exchange requests
With concurrent request handling, the periodic registry refresh now writes these strings while GoogleAuthService::exchangeCodeForUser reads them to validate credentials and construct its token request. The equivalent new setters for WeChat and GitHub have the same problem. These are unsynchronized reads and writes to std::string, so even an unchanged row reapplied every 60 seconds introduces undefined behavior, potentially corrupting requests or crashing the server. Protect updates and reads together, and take one consistent credential-pair snapshot for each exchange.
Useful? React with 👍 / 👎.
| { | ||
| disabledProviders_.insert(provider); | ||
| } | ||
| buildBody(); |
There was a problem hiding this comment.
Synchronize rebuilding the provider discovery cache
In the multithreaded production configuration, every refresh with a legacy row calls this setter and buildBody(), which replaces cachedBody_, while AuthProvidersController::list() copies that same JSON value without synchronization. The cache was previously only built during startup, so making it runtime-mutable introduces a data race on ordinary discovery requests, even when no administrator changes anything. Serialize both cache publication and reads, or publish an immutable snapshot atomically; also protect the mutable provider collections against overlapping refreshes.
Useful? React with 👍 / 👎.
| std::lock_guard<std::mutex> stateLock(self->legacyMutex_); | ||
| self->legacyState_ = std::move(legacyState); |
There was a problem hiding this comment.
Remove legacy runtime entries when their registry rows disappear
After an enabled legacy row has been applied, deleting it through UpstreamProviderAdminController::remove() triggers a refresh, but this loop only applies rows that still exist. Replacing legacyState_ with an empty map does not remove the existing guard entry, clear the service credentials, or hide the discovery entry. Thus deleting an enabled Google, WeChat, or GitHub row leaves it usable and advertised for the remainder of the process, unlike deletion of a dynamic upstream. Reconcile previously applied legacy keys against the new records and explicitly disable removed keys.
Useful? React with 👍 / 👎.
…mbdas cannot capture statics)
Purpose
P2-1 batch C: google/wechat/github migrate onto the upstream registry — config becomes the first-boot seed only; afterwards the DB row is the runtime source of truth. Admin credential rotation and enable/disable now take effect without a restart.
Semantics
external_auth.*when credentials are configured (tier-gated enablement).ON CONFLICTis ignored — admin edits to the rows win and survive restarts. Deployments that never configured social keep the exact pre-P2-1c behavior (no rows, nothing advertised).setCredentialshot swap on all three),updateStaticProvider: new creds + state binding;enabled=falseremoves the key → authorize/validate 404; an enabled row may enable a provider config never configured),buildSocialAuthorizeUrlWithCredentials— byte-identical to the historical config-based shapes (the config builder now delegates to it).setGuardTargetreplays legacy state), so the social mock fixture's guard swap keeps the registry functional in-process.Tests
New integration case
Integration_P2_UpstreamRegistry_LegacySocialRowDrivesStaticSurface(postgres legs): SQL-seeded enabled github row → login page lists it → authorize transaction carries the ROW credentials in the pinned GitHub URL shape → admin PUT disables → listing drops it + authorize 404s → admin CREATE still rejects reserved keys.Verification
--force— additive members to public classes, and v1.x promises source-level SemVer only (SDK guide §2)