Repository navigation
feat(oidc-in): P2-1a upstream provider registry + generic OIDC federation core - #347
Conversation
…tion core
- V045 upstream_providers table (+ generated ORM model)
- identity: IUpstreamProviderRepository port + OidcUpstreamAuthService
(discovery cache / authorize URL / code exchange / userinfo claims
mapping / AccountLinkFlow reuse; injectable transport seams)
- storage-postgres: PostgresUpstreamProviderRepository (async Mapper)
- drogon: SocialLoginGuard dynamic providers + authorize-URL build;
UpstreamProviderRuntime (refresh glue, 60s loop); UpstreamLoginController
(/api/auth/oidc/{provider}/login); UpstreamProviderAdminController
(/api/admin/upstream-providers CRUD, roles:read/write, secret
write-only); login-page listing merges registry entries
- wiring: IdentityAssembly/ControllerRegistration/test_main
- tests: OidcUpstreamAuthServiceTest (fakes) + admin CRUD/login-guard
integration (hermetic via endpoint_overrides)
- openapi.yaml: 6 new operations + schemas (enum opened for registry keys)
- route manifest + Property4 fingerprint (sorted) + migration/api-diff baselines ratified; openapi.json regenerated; python/go/ts clients regenerated from the updated spec - SocialMockFixture injectLoginGuard re-binds the UpstreamProviderRuntime onto the test guard (setGuardTarget) so registry providers stay authorizable inside the test process; runtime gains buildDynamic() shared by commit()/setGuardTarget() - identity service drops trantor logging (layer is drogon-free); controller/regstration include fixes; unique_lock corrections; unit-test namespace/capture fixes
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: 83d98833a6
ℹ️ 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".
| endpoints.authorize = overrides.get("authorize", "").asString(); | ||
| endpoints.token = overrides.get("token", "").asString(); | ||
| endpoints.userinfo = overrides.get("userinfo", "").asString(); |
There was a problem hiding this comment.
Validate endpoint override value types before persisting them
An admin request containing endpoint_overrides: {"token": {}} passes parseBody() because validation only checks that the outer value is an object. The mutation then invokes refresh(), and these asString() calls throw for the nested object inside the asynchronous repository callback. With no exception handler around endpoint resolution, malformed persisted configuration can terminate the server again on startup or periodic refresh. Validate individual override values as strings before saving and make endpoint resolution report malformed configuration through its callback.
Useful? React with 👍 / 👎.
| lock.unlock(); | ||
| self->commit(std::move(records), std::move(endpointsMap)); |
There was a problem hiding this comment.
Reject stale refresh results before publishing the snapshot
If a periodic refresh reads an enabled provider and waits on discovery, an intervening admin disable/delete can complete its own refresh and remove that provider. When the older discovery request finishes, this unconditional commit republishes the old enabled record and restores it to SocialLoginGuard; findForLogin() also trusts that stale snapshot, so authentication remains available despite the successful disable/delete until another refresh corrects it. Assign refresh generations and prevent older results from overwriting a newer published snapshot.
Useful? React with 👍 / 👎.
| ::drogon::HttpClient::newHttpClient(host, ::drogon::app().getLoop()) | ||
| ->sendRequest(req, [cb = std::make_shared< | ||
| fulla::identity::OidcUpstreamAuthService::FetchCallback>(std::move(cb))]( |
There was a problem hiding this comment.
Contain exceptions when constructing upstream HTTP requests
The admin validator accepts an issuer such as https:// because it only checks the scheme prefix. Discovery then reaches this HTTP-client construction with an empty host, and transport setup exceptions escape the asynchronous refresh callback rather than producing a failed discovery result. The existing DrogonOAuthHttpClient.cc explicitly guards this same malformed-host failure in both transport methods, but the new GET and form-POST seams bypass those guards. Reuse that adapter or catch transport setup exceptions in both seams and invoke the failure callback so a bad registry URL cannot terminate the server.
Useful? React with 👍 / 👎.
…ng in oasdiff ignore
…this on a stack object threw bad_weak_ptr)
Purpose
P2-1 batch A (roadmap v1.7.0): the OIDC-in generic upstream federation registry — DB-driven upstream providers, the generic authorize/exchange protocol, and admin CRUD. Batch B (Keycloak E2E), C (google/wechat/github migration onto the registry), D (admin UI) follow.
What lands
Storage & domain
V045__upstream_providers.sql: registry table (provider_key/display_name/issuer/client creds/scopes/claims_mapping/endpoint_overrides/enabled; key-format CHECK; partial index on enabled)IUpstreamProviderRepositoryport +PostgresUpstreamProviderRepository(async Mapper, vector-callback idiom; UNIQUE(provider_key) →duplicate_keytoken)OidcUpstreamAuthService(identity layer, drogon-free): discovery fetch with 10-min per-issuer cache → authorize-URL builder (pure) → code exchange (client_secret_post) → userinfo → claims mapping (defaultssub/email/preferred_username/name) → reuses the same AccountLinkFlow as google/wechat/github (oauth2_subject_mappings.provider = provider_key). HTTP is injected via two transport seams — the whole protocol is unit-tested without a live upstream.Drogon layer
SocialLoginGuardgains a dynamic provider set: registry keys ride the exact same origin/binding-cookie/one-time-state machinery as the social providers; the authorize URL is built from the pre-resolved endpoint (endpoint_overrides or last discovery) so the guard stays synchronous.UpstreamProviderRuntime: refresh glue (list enabled → resolve endpoints → push to guard) + 60s loop; admin mutations refresh immediately.UpstreamLoginController—POST /api/auth/oidc/{provider}/login(same {code,state} contract and first-party token-pair response as the social logins, via SocialTokenIssuer).UpstreamProviderAdminController—/api/admin/upstream-providersCRUD (roles:read/roles:writeper the claim-mappings precedent; client_secret is write-only —client_secret_setbool only, empty on update keeps it). Reserved social keys are rejected upfront.GET /api/auth/providersmerges registry entries (type: "oidc",display_name) into the login-page listing; the authorize endpoint accepts registry keys.Sync points (all updated): openapi.yaml (6 operations + 2 schemas; provider enums opened for registry keys), route manifest, Property4 fingerprint (sorted), migration + api-diff baselines ratified,
docs/api/openapi.jsonregenerated, python/go/ts clients regenerated.Tests
OidcUpstreamAuthServiceTest, 9 cases): authorize-URL escaping, overrides short-circuit, discovery parse + per-issuer cache + issuer-mismatch failure, happy-path create (form fields asserted), existing-mapping no-create, custom claims mapping + missing-sub refusal, auto-create-off refusal, upstream failure mapping.injectLoginGuard()re-binds the runtime onto the test guard so the registry keeps working inside the test process.Verification