Commit Graph

4 Commits (06eeb95b4e050ede712ef16fb6053e4fa5fcfbde)

Author SHA1 Message Date
wizardchen a55b09ea82 refactor(auth): unify session-context attachment and split the Auth middleware
The five near-identical "c.Set + context.WithValue" blocks (JWT branch,
tenantless branch, both API-key attach helpers, EmbedAuth) now go through
one applyAuthSession helper, so the c.Keys surface and the request-context
surface can no longer drift apart. The 140-line JWT branch inside Auth is
split into authenticateJWTUser / resolveTargetTenant, which also removes a
duplicate GetTenantByID roundtrip on the X-Tenant-ID switch path.

Fixes folded in:
- delete GetTenantIDFromContext: it read ctx.Value("tenantID") while the
  value is stored under types.TenantIDContextKey ("TenantID"), so it could
  never succeed (dead, broken, uncalled)
- isPlatformTenantOptionalAPI: match "/api/v1/system/admin" exactly or as
  a "/"-delimited prefix instead of a bare HasPrefix that would also admit
  sibling paths sharing the prefix
- 401 for a presented-but-invalid Bearer token now says "invalid or
  expired token" instead of the misleading "missing authentication"
- replace the remaining log.Printf calls in the auth path with the
  request-scoped structured logger

New tests lock the both-surfaces invariant of applyAuthSession, the
tenantless "no tenant/role keys" contract, and bearerToken parsing.
2026-07-27 11:25:23 +08:00
wizardchen 41975abcc5 refactor(terminology): rename user-facing tenant labels to workspace
Align product copy, API docs, Swagger descriptions, and i18n strings
with workspace terminology while keeping internal tenant identifiers
and headers unchanged for API compatibility.
2026-07-14 16:14:43 +08:00
wizardchen cb99736d72 feat: scope API MCP OAuth by principal 2026-06-30 20:01:05 +08:00
wizardchen ed9802ff2b feat(embed): add backend embed channels with auth and rate limiting (#1657)
Introduce embed_channels storage, publish-token and session-token auth,
origin allowlist enforcement, shared Redis rate limiter, public embed API
routes, webhooks with SSRF validation, and session listing by embed source.
2026-06-12 23:10:39 +08:00