Skip to content

feat(clients): Python + Go client SDKs (C1: M1+M2 clients, M3 release wiring, M4 docs) - #65

Merged
voidvec merged 12 commits into
masterfrom
feat/client-sdk-python-go
Aug 19, 2026
Merged

voidvec merged 12 commits into
masterfrom
feat/client-sdk-python-go

Conversation

@voidvec

@voidvec voidvec commented Aug 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Implements task C1 (next-phase plan, third tier): the Python + Go client SDKs (design M1-M4), on top of the merged M0 spec governance (v1.2.0).

  • M1 Python (clients/python): generated typed surface (openapi-python-client 0.29.0, 157 files, DO-NOT-EDIT) + handwritten auth layer — m2m_client/async_m2m_client (client_credentials with proactive refresh + one 401-triggered retry, thread/asyncio-safe), basic_auth_client (introspect/revoke per RFC 7662 §2.1), one-shot fetch_client_credentials_token, AuthorizationCodeFlow + PkcePair (S256). Distribution name authforge-oauth2, import name authforge.
  • M2 Go (clients/go): oapi-codegen v2.8.0 generated client + auth package — NewM2MClient (x/oauth2 clientcredentials, AuthStyleInHeader per F-017), FetchClientCredentialsToken, NewBasicAuthClient, AuthCodeFlow/PKCE. Module github.com/lucaswang420/authforge/clients/go.
  • Drift gate + CI: tools/clients/regen_clients.py (pinned generators, --check, version-linkage --version-only, --selftest) + new clients-sdk.yml (path-filtered; python/go jobs with drift + unit tests; kept out of source-only static-checks).
  • M3 wiring: release.yml gains sdk-python (version backstop + build always; PyPI publish tag+secret gated via job-env + step-if — the secrets context cannot drive a job-level if) and pushes the nested clients/go/v<version> tag on release (subdirectory modules are invisible to root tags).
  • M4 docs: bilingual README "Path D" sections, per-client READMEs, e2e example (clients/python/examples/client_credentials_demo.py), design addendum §十一 + implementation plan with acceptance criteria (both in docs/productization-evolution/in-progress/).

Design deviations found by field validation (all documented in §十一)

  1. PyPI naming: authforge and authforge-sdk on PyPI are taken by unrelated projects → distribution authforge-oauth2 (import authforge).
  2. Go publishing is not zero-work: subdirectory modules resolve from nested tags → release.yml now creates clients/go/v<version>.
  3. Spec bug fixed en route: OAuth2Error enum lacked invalid_token/insufficient_scope (RFC 6750 §3.1 codes that userinfo 401/403 actually return per the YAML's own descriptions) — generated clients crashed parsing real 401s. oasdiff verdict: 24 warnings, 0 breaking errors (enum widening). api-reference.md already documented these codes; the YAML now matches.

Review

Design + plan were deep-reviewed by a code-architect pass (findings recorded in the implementation plan's appendix): 5 blocking issues fixed before implementation (nested Go tags, issuer fallback assertion, server-boot recipe, secrets-context gating, release-time version backstop), 6 improvements adopted.

Verification

Check Result
Python unit (MockTransport, P1-P8 matrix) 25/25 green
Go unit (httptest, G1-G8 incl. concurrency + 1s-expiry refresh + RFC 7636 vector) all green, vet+gofmt clean
Integration I1-I5 vs live full stack (PG + seeds, both languages) 5/5 + 5/5 green
Drift fault injection (edit generated file → --check) exit 1 → restore → exit 0
python -m build clients/python sdist+wheel, 157 generated files + py.typed in wheel
CI static checks (arch/migration/api-diff/naming/parity/spec-validator/governance selftest+run/diff-endpoint-baseline) all green locally
oasdiff breaking (base vs head spec) 0 errors (24 enum-widening warnings)
actionlint v1.7.12 (release.yml + clients-sdk.yml) 0 findings (release.yml is tag-triggered, never parsed by CI on this branch)
security-check.sh / doc-links pre-existing warnings only; my 5 link regressions fixed, stale research links repaired
Full backend suite (full_test.bat 8 steps) 8/8 PASS (462 ctest, 0 failed; OAuth2 + 55/55 admin endpoint tests)
Full frontend suite admin build + 168 passed/6 skipped e2e; user build + 98 e2e + 21 unit tests

Versioning

No version bump in this PR (repo convention: separate chore(release) commit + tag). clients/python/pyproject.toml stays at 1.2.0 == cmake (enforced by the new gates). After merge, release v1.3.0 (minor: new clients) via the usual flow.

Follow-ups (out of scope)

  • One-time PyPI setup before first publish: register authforge-oauth2, add PYPI_API_TOKEN repo secret (the release job prints this hint when the secret is absent). AC7 publish smoke belongs to that release.
  • Spec wording nit (review B1): /oauth2/token description mentions body-form client credentials while F-017 restricts that to client_secret_post clients — candidate follow-up spec clarification.
  • release.yml dry-run dispatch (workflow_dispatch) to watch sdk-python skip-on-missing-secret, after merge.

- client-sdk-facility-design.md v1.2: addendum section 11 (generator
  field-validation, PyPI naming collision -> authforge-oauth2 dist name,
  layout finalization, auth injection seams, drift-gate placement,
  release wiring corrections incl. Go nested-tag requirement)
- move design doc todo/ -> in-progress/ (Layer 2 now started), fix all
  inbound references
- new client-sdk-implementation-plan.md: W1-W6 work items with
  acceptance criteria; incorporates code-architect review findings
  (5 blocking fixes, 6 improvements)
Cross-platform single script (repo tools convention: --selftest, exit
0/1/2, ASCII tags) that regenerates clients/python + clients/go from
apps/server/openapi.yaml with pinned generators and, with --check,
diffs against the committed trees (newline-normalized for Windows
autocrlf checkouts). --version-only guards the pyproject <-> cmake
version linkage (release backstop). Selftest covers tree-diff fault
injection, version parse/sync, and ignore filters.
…ten auth layer

- clients/python: distribution authforge-oauth2 (import name authforge);
  src/authforge/generated/ regenerated from openapi.yaml (157 files,
  openapi-python-client 0.29.0, DO NOT EDIT)
- m2m.py: ClientCredentialsAuth/AsyncClientCredentialsAuth (httpx.Auth)
  with proactive refresh (clock-skew margin), single 401-triggered
  retry, thread/asyncio-safe locking; m2m_client/async_m2m_client
  factories inject into the generated AuthenticatedClient via
  set_httpx_client (bypasses its static bearer header); basic_auth_client
  for introspect/revoke (F-017 client_secret_basic); one-shot
  fetch_client_credentials_token
- oauth.py: AuthorizationCodeFlow (authorize URL + PKCE S256 + code
  exchange + refresh rotation helper), RFC 7636 appendix B vector tested
- openapi.yaml: OAuth2Error enum += invalid_token, insufficient_scope
  (RFC 6750 section 3.1 codes the userinfo 401/403 responses already
  documented; without them the generated client cannot parse real 401s).
  oasdiff verdict: warnings only (response-property-enum-value-added),
  0 breaking errors
- unit tests 25 green (MockTransport, no server); integration suite
  env-gated (AUTHFORGE_BASE_URL)
…auth layer

- clients/go: module github.com/lucaswang420/authforge/clients/go
  (go 1.24; oapi-codegen/runtime v1.7.0); generated/client.gen.go
  regenerated from openapi.yaml (oapi-codegen v2.8.0, DO NOT EDIT)
- auth/clientcredentials.go: NewM2MClient (x/oauth2 clientcredentials,
  AuthStyleInHeader per F-017 -- cached + auto-refresh + goroutine-safe),
  FetchClientCredentialsToken one-shot, NewBasicAuthClient for
  introspect/revoke (RFC 7662 2.1 calling-client Basic)
- auth/authcode.go: AuthCodeFlow (authorize URL + PKCE S256 + exchange +
  refresh, confidential Basic / public form client_id), TokenResponse,
  ParseAuthorizationResponse
- auth/pkce.go + auth/errors.go: RFC 7636 helpers; AuthError unwraps
  x/oauth2 RetrieveError into the RFC 6749 error body
- unit tests green (httptest: G1-G8 matrix incl. concurrency caching,
  1 s-expiry auto refresh, RFC 7636 appendix B vector, Basic-on-exchange);
  integration suite behind -tags integration + AUTHFORGE_BASE_URL
…(M3 wiring, M4)

- clients-sdk.yml (new): PR path-filtered drift gate + unit tests for
  both clients (python: pinned generator + pytest; go: build/vet/gofmt +
  tests); kept out of static-checks (source-only) per design 11.5
- release.yml: new sdk-python job (version-linkage backstop, sdist+wheel
  always; PyPI publish tag+secret gated via job env + step if -- the
  secrets context cannot drive a job-level if); github-release job now
  pushes the nested clients/go/v<version> tag Go module resolution
  requires (subdirectory modules are invisible to root tags)
- README.md / README.zh-CN.md: 'Path D -- Client SDKs' section
- next-phase-implementation-plan.md: C1 marked delivered with deviations
  (PyPI naming, nested tags, OAuth2Error enum fix); progress-status.md,
  productization-evolution README index, design doc AC table (AC4-AC6
  evidenced, AC7 explicitly pending publish)
…esearch link

The doc-link checker caught 5 links my earlier path rewrites got wrong
(../in-progress/ from same-directory files, sibling governance-plan link
after the move) plus the pre-existing ../productization-research.md typos
in productization-evolution-plan.md; remaining 2 broken links are local
.zcode session artifacts, out of repo scope.
The YAML now feeds clients/python + clients/go; the skill workflow (and
its three tool mirrors) tells editors to run the regen tool after spec
edits and keep the pyproject/cmake version linkage in mind on bumps.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

The auth layer keeps a private httpx client for token I/O (separate on
purpose, so token fetches never recurse through auth_flow); closing only
the returned AuthenticatedClient leaked that pool until GC -- the async
flavour leaked transports on a possibly-closed loop. The generated attrs
classes are slotted, so close_m2m_client()/close_async_m2m_client()
reach the auth object through the injected client's .auth field and
close both pools. Tests assert both pools report closed; README and
design doc 11.4 document the semantics.
@voidvec

voidvec commented Aug 18, 2026

Copy link
Copy Markdown
Owner Author

Self-review outcome

A code-reviewer pass over the handwritten surfaces (Python auth layer + tests, Go auth package + tests, regen tool, both workflows, packaging) came back with one high-confidence finding, fixed in 5cae993:

  • Token-pool leak — m2m_client()/async_m2m_client() left the auth layer's private token-endpoint httpx client unreachable for cleanup (generated attrs classes are slotted; closing the returned AuthenticatedClient only closed the injected API client; the async flavour leaked transports on a possibly-closed loop). Fixed with close_m2m_client()/close_async_m2m_client() (reaches the auth object via the injected client's .auth field, closes both pools); two new tests assert both pools report closed; README + design doc §11.4 document the semantics.

Everything else was verified clean, notably: httpx sync auth_flow/async_auth_flow pairing, 401 retry-once with form-body resend, F-017 Basic-only honored in all Go paths, RoundTrip clone semantics, drift-gate determinism, the secrets-in-job-env + step-if publish gating, and the nested clients/go/v* tag push being loop-free (contents: write + fetch-depth: 0 already present).

CI so far: clients-sdk (python+go), static-checks, frontend, oasdiff, security — all green; the three C++ build-test matrix jobs are running (this PR does not touch C++ sources).

…r slowness; master average ~20m, this PR changes zero C++ build inputs)
…een)

- clients-sdk.yml + release.yml pass actionlint v1.7.12 with zero
  findings; release.yml is tag-triggered so CI never parsed it on this
  branch -- static validation closes that gap
- both Client SDKs jobs verified SUCCESS on PR #65 checks
- W5 dispatch dry-run box stays open: pre-merge dispatch attempt was
  rejected (PAT lacks Actions write, 403); post-merge dispatch from the
  Actions UI remains the plan, publish-step skip logic is static-gated
  (ref_type == 'tag' && secret) so dispatch cannot publish
@voidvec
voidvec merged commit 6558b7c into master Aug 19, 2026
11 checks passed
voidvec added a commit that referenced this pull request Aug 22, 2026
Frontends' package.json synced to 1.3.0 (the cmake/CMakeLists/conanfile/
pyproject/openapi bumps landed with PR #68); CHANGELOG curated for the
two mainlines since v1.2.0: C1 client SDKs (Python authforge-oauth2 + Go,
PR #65) and B2 social account link/unlink (PR #68). 21 commits, purely
additive minor.
@voidvec
voidvec deleted the feat/client-sdk-python-go branch August 29, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants