Compare commits

116 Commits

Author SHA1 Message Date
Zayden-Jung 0c34703ec7 Merge pull request '将 Bedrock 主线切换为 Rust 初始项目 [skip ci]' (#23) from codex/bedrock-rust into main
Reviewed-on: #23
2026-11-29 15:35:46 +00:00
codex-bot 59f2ef1bf2 Replace legacy Go project with Rust Bedrock bootstrap 2026-11-29 23:33:11 +08:00
Zayden-Jung fa79b1e6ce Merge pull request '将共享后端改名为 Bedrock [skip ci]' (#22) from codex/bedrock-rename into main
Reviewed-on: #22
2026-11-19 11:44:44 +00:00
codex-bot 6fcfbf1def Rename shared backend to Bedrock [skip ci] 2026-11-19 19:30:05 +08:00
codex-bot 3bc3051383 Merge PR #21: 补充 Foundry 入口注册与部署注释 [skip ci] 2026-11-19 11:20:45 +00:00
codex-bot 53bc8d73eb docs: explain deployment stages and separate comment sections [skip ci] 2026-11-17 00:01:26 +08:00
codex-bot 00fd89af1a docs: explain Foundry HTTP module registration [skip ci] 2026-11-16 21:18:25 +08:00
Zayden-Jung 27412f58af Merge pull request 'docs: 补充 Foundry 全仓中文源码与部署注释 [skip ci]' (#20) from codex/chinese-source-comments into main
Reviewed-on: Zayden-Jung/foundry-core#20
2026-11-16 10:04:35 +00:00
codex-bot 1090591503 docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci] 2026-11-16 17:59:10 +08:00
Zayden-Jung 30829eeb86 Merge pull request 'Add canonical canvas edits, identity migration and idempotent resource/AI operations' (#19) from codex/headless-canvas-v1 into main
Foundry Go checks / check (push) Successful in 3m25s
Deploy Foundry Core / deploy (push) Successful in 3m10s
Reviewed-on: Zayden-Jung/foundry-core#19
2026-11-11 14:53:33 +00:00
codex-bot 506f778ac3 fix(canvas): retain canonical frame rotation across owner changes
Foundry Go checks / check (push) Successful in 3m26s
Foundry Go checks / check (pull_request) Successful in 3m28s
2026-11-11 18:53:06 +08:00
codex-bot 36d69133b8 ci(canvas): verify owning-canvas dissolution and receipt recovery
Foundry Go checks / check (push) Failing after 3m15s
Foundry Go checks / check (pull_request) Failing after 3m8s
2026-11-11 18:42:55 +08:00
codex-bot 5db2bf3c98 ci(canvas): verify the browser migration delivery revision
Foundry Go checks / check (push) Successful in 3m23s
Foundry Go checks / check (pull_request) Successful in 3m18s
2026-11-11 18:06:55 +08:00
codex-bot 3268c57bc6 ci(canvas): verify durable migration coordination with the actual client
Foundry Go checks / check (push) Successful in 3m27s
Foundry Go checks / check (pull_request) Successful in 3m36s
2026-11-11 17:11:14 +08:00
codex-bot d00388504c test(canvas): cover migration admission guards with valid legacy edges
Foundry Go checks / check (push) Successful in 3m36s
Foundry Go checks / check (pull_request) Successful in 3m25s
2026-11-11 16:35:31 +08:00
codex-bot cc3068ace3 test(canvas): verify canonical concurrency and late migration rollback
Foundry Go checks / check (push) Failing after 2m59s
Foundry Go checks / check (pull_request) Failing after 2m55s
2026-11-11 16:29:37 +08:00
codex-bot 1605b5a9d6 ci(canvas): verify managed result copy with durable source files
Foundry Go checks / check (push) Successful in 3m43s
Foundry Go checks / check (pull_request) Successful in 3m36s
2026-11-11 16:09:57 +08:00
codex-bot ca01ea3ea1 ci(canvas): verify host asset display and original generated bytes
Foundry Go checks / check (push) Failing after 3m18s
Foundry Go checks / check (pull_request) Failing after 3m45s
2026-11-11 16:04:44 +08:00
codex-bot 8395baa24f ci(canvas): verify cancellation cursor drain in real client
Foundry Go checks / check (push) Failing after 3m27s
Foundry Go checks / check (pull_request) Failing after 3m25s
2026-11-11 15:55:58 +08:00
codex-bot daec39ead4 ci(canvas): exercise controlled HTTP run polling
Foundry Go checks / check (push) Failing after 3m8s
Foundry Go checks / check (pull_request) Failing after 3m24s
2026-11-11 15:50:45 +08:00
codex-bot 121ce7496c ci(canvas): verify headless AI v2 negotiation fix
Foundry Go checks / check (push) Failing after 3m25s
Foundry Go checks / check (pull_request) Failing after 3m20s
2026-11-11 15:42:24 +08:00
codex-bot c8f3940d26 ci(canvas): pin AI protocol header trace
Foundry Go checks / check (push) Failing after 3m14s
Foundry Go checks / check (pull_request) Failing after 3m23s
2026-11-11 15:35:05 +08:00
codex-bot da6a5f8207 ci(canvas): expose AI admission recovery diagnostics
Foundry Go checks / check (push) Failing after 3m18s
Foundry Go checks / check (pull_request) Failing after 3m23s
2026-11-11 15:29:02 +08:00
codex-bot 6131fb5d7b Verify runtime AI coordination against real HTTP and database state
Foundry Go checks / check (push) Failing after 3m45s
Foundry Go checks / check (pull_request) Failing after 3m12s
2026-11-11 15:13:14 +08:00
codex-bot 28ca98a506 Verify current headless client through the remote HTTP integration runner
Foundry Go checks / check (push) Successful in 3m22s
Foundry Go checks / check (pull_request) Successful in 3m22s
2026-11-11 14:24:48 +08:00
codex-bot 95812c3a96 Verify asset permission revocation and immutable adoption rejection receipts
Foundry Go checks / check (push) Successful in 5m12s
Foundry Go checks / check (pull_request) Successful in 5m0s
2026-11-09 16:36:19 +08:00
codex-bot efa916060a Preserve private asset metadata headers and verify cross-project adoption
Foundry Go checks / check (push) Successful in 3m48s
Foundry Go checks / check (pull_request) Successful in 3m32s
2026-11-09 16:12:36 +08:00
codex-bot cc2ca05cd4 Pin real asset metadata and original byte verification client
Foundry Go checks / check (push) Failing after 3m28s
Foundry Go checks / check (pull_request) Failing after 2m55s
2026-11-09 15:55:20 +08:00
codex-bot be2014cc31 Avoid ambiguous asset metadata and operation receipt routes
Foundry Go checks / check (push) Failing after 3m7s
Foundry Go checks / check (pull_request) Failing after 3m28s
2026-11-09 15:49:58 +08:00
codex-bot 6b07c19728 Expose permission-checked immutable asset metadata for shared depot adoption
Foundry Go checks / check (push) Failing after 6m24s
Foundry Go checks / check (pull_request) Failing after 4m36s
2026-11-09 15:47:19 +08:00
codex-bot 6a0a2e1912 Pin upload Created-response fault injection coverage
Foundry Go checks / check (push) Successful in 3m7s
Foundry Go checks / check (pull_request) Successful in 2m59s
2026-11-09 14:43:25 +08:00
codex-bot 7d7408a0ec Verify scoped image upload and lost receipt recovery with the live headless client
Foundry Go checks / check (push) Failing after 3m5s
Foundry Go checks / check (pull_request) Failing after 3m1s
2026-11-09 14:37:30 +08:00
codex-bot ee04a6372b Pin live partial-scope import and deep-copy integration coverage
Foundry Go checks / check (push) Successful in 4m19s
Foundry Go checks / check (pull_request) Successful in 3m58s
2026-11-09 14:05:21 +08:00
codex-bot d6e877712a Pin corrected Foundry HTTP consumer transport
Foundry Go checks / check (push) Successful in 10m19s
Foundry Go checks / check (pull_request) Successful in 3m41s
2026-11-09 13:50:50 +08:00
codex-bot 6d1a5b5c83 Run pinned Endoleap headless runtime against real HTTP and PostgreSQL in CI
Foundry Go checks / check (push) Failing after 4m1s
Foundry Go checks / check (pull_request) Failing after 4m15s
2026-11-09 13:45:40 +08:00
codex-bot 9cf6e4cedf Bind all canvas element identities to their snapshot owners
Foundry Go checks / check (push) Successful in 2m53s
Foundry Go checks / check (pull_request) Successful in 2m55s
2026-11-09 04:11:26 +08:00
codex-bot ad6ab30b5f Declare snapshot-bound direct canvas membership counts in model streams
Foundry Go checks / check (push) Successful in 5m54s
Foundry Go checks / check (pull_request) Successful in 5m45s
2026-11-09 03:36:37 +08:00
codex-bot 789edcc61b ci: allow cold Go toolchain setup in backend checks
Foundry Go checks / check (push) Successful in 23m24s
Foundry Go checks / check (pull_request) Successful in 23m10s
2026-11-09 02:25:20 +08:00
codex-bot e38254821a Stream negotiated canonical model reads with snapshot framing
Foundry Go checks / check (push) Failing after 10m37s
Foundry Go checks / check (pull_request) Failing after 10m45s
2026-11-09 02:01:46 +08:00
codex-bot ff88865e91 test(canvas): restore a lifetime canceled before its first request
Foundry Go checks / check (push) Successful in 7m0s
Foundry Go checks / check (pull_request) Successful in 5m51s
2026-11-08 04:50:09 +08:00
codex-bot fb1bf4ab85 test(canvas): verify compacted logical coverage and lifecycle records
Foundry Go checks / check (push) Successful in 7m23s
Foundry Go checks / check (pull_request) Successful in 7m40s
2026-11-08 04:36:44 +08:00
codex-bot ca90b3fea3 test(canvas): verify ordered batch receipts and rollback
Foundry Go checks / check (push) Successful in 6m1s
Foundry Go checks / check (pull_request) Successful in 5m52s
2026-11-08 04:28:15 +08:00
codex-bot 31258b995f Avoid duplicate geometry fixture variable in scaled-move coverage
Foundry Go checks / check (push) Successful in 6m34s
Foundry Go checks / check (pull_request) Successful in 3m12s
2026-11-08 02:54:31 +08:00
codex-bot 24b27dcac4 Verify atomic scaled-container unit metadata and inverse writes
Foundry Go checks / check (push) Failing after 4m12s
Foundry Go checks / check (pull_request) Failing after 1m51s
2026-11-08 02:52:29 +08:00
codex-bot d6690c3764 Verify current-owner permissions before moved AI execution
Foundry Go checks / check (push) Successful in 3m4s
Foundry Go checks / check (pull_request) Successful in 2m54s
2026-11-08 01:24:53 +08:00
codex-bot c9bb38454d Preserve relocation context for conflicted AI outputs
Foundry Go checks / check (push) Successful in 3m13s
Foundry Go checks / check (pull_request) Successful in 2m57s
2026-11-08 01:20:06 +08:00
codex-bot 2d4aefbdc0 Remove dependent connections in moved-target deletion fixture
Foundry Go checks / check (push) Successful in 2m51s
Foundry Go checks / check (pull_request) Successful in 3m3s
2026-11-08 01:16:51 +08:00
codex-bot 56b6181598 Resolve canonical AI targets at their current canvas owner
Foundry Go checks / check (push) Failing after 2m49s
Foundry Go checks / check (pull_request) Failing after 2m41s
2026-11-08 01:16:28 +08:00
codex-bot cdf48f1691 Verify AI replan and cancellation completion boundaries
Foundry Go checks / check (push) Successful in 2m54s
Foundry Go checks / check (pull_request) Successful in 2m52s
2026-11-08 01:04:34 +08:00
codex-bot f12c4ad8bd Persist queryable AI action outcomes and zero-effect rejection receipts
Foundry Go checks / check (push) Successful in 2m51s
Foundry Go checks / check (pull_request) Successful in 3m6s
2026-11-08 00:53:11 +08:00
codex-bot 00ff738705 Bind canonical AI admission to the project version vector
Foundry Go checks / check (push) Successful in 2m52s
Foundry Go checks / check (pull_request) Successful in 2m58s
2026-11-08 00:28:13 +08:00
codex-bot fa76773efc Apply canonical AI outputs through scoped identity-checked changes
Foundry Go checks / check (push) Successful in 2m56s
Foundry Go checks / check (pull_request) Successful in 2m47s
2026-11-08 00:23:00 +08:00
codex-bot 0d7fc4dbe5 Preserve staged resource identities and expose upload receipts
Foundry Go checks / check (push) Successful in 2m56s
Foundry Go checks / check (pull_request) Successful in 2m49s
2026-11-07 23:18:20 +08:00
codex-bot bf8763e0de Preserve opaque JSON keys independently of field write guards
Foundry Go checks / check (push) Successful in 2m51s
Foundry Go checks / check (pull_request) Successful in 2m45s
2026-11-07 22:52:31 +08:00
codex-bot 4a89137e38 Embed protocol fixture for isolated integration test binaries
Foundry Go checks / check (push) Successful in 2m42s
Foundry Go checks / check (pull_request) Successful in 2m49s
2026-11-07 22:47:16 +08:00
codex-bot b7499e3815 Verify canonical partition restoration and frontend protocol fixture
Foundry Go checks / check (push) Failing after 3m6s
Foundry Go checks / check (pull_request) Failing after 2m36s
2026-11-07 22:40:39 +08:00
codex-bot 12458e10dc Fix canonical archive writes and retain scoped lifecycle evidence
Foundry Go checks / check (push) Successful in 2m41s
Foundry Go checks / check (pull_request) Successful in 2m40s
2026-11-07 22:34:42 +08:00
codex-bot b85e8bd2ca Add canonical canvas rows, stable identity migration and model operations
Foundry Go checks / check (push) Failing after 2m29s
Foundry Go checks / check (pull_request) Failing after 2m31s
2026-11-07 22:26:06 +08:00
codex-bot 19884b2a90 Stage atomic canvas operation batches and durable receipts
Foundry Go checks / check (push) Successful in 2m40s
Foundry Go checks / check (pull_request) Successful in 2m39s
2026-11-07 22:05:06 +08:00
Zayden-Jung 9f01aa3db8 Merge pull request '移除论文精确计数并优化游标与领域查询 [skip ci]' (#18) from codex/research-cursors into main
Reviewed-on: Zayden-Jung/foundry-core#18
2026-11-07 09:30:23 +00:00
codex-bot 026ee22c1e Page research without exact counts and bound candidate scans [skip ci] 2026-11-07 17:27:35 +08:00
Zayden-Jung 142c7b2d86 Merge pull request '共享 PostgreSQL 论文只读 API [skip ci]' (#17) from codex/research-api into main
Reviewed-on: Zayden-Jung/foundry-core#17
2026-11-07 08:23:36 +00:00
codex-bot 9dd166d5de Finalize research API validation and handoff notes [skip ci] 2026-11-07 16:13:36 +08:00
codex-bot 1363792bb0 Read the published research corpus and avoid expensive paging plans [skip ci] 2026-11-07 15:51:17 +08:00
codex-bot 913bf4292b Verify research SQL and read-only permissions in isolated PostgreSQL CI
Foundry Go checks / check (push) Successful in 3m43s
Foundry Go checks / check (pull_request) Successful in 4m1s
2026-11-07 02:44:55 +08:00
codex-bot 028e453d92 Prepare read-only PostgreSQL paper queries and optional Core wiring
Foundry Go checks / check (push) Successful in 3m57s
Foundry Go checks / check (pull_request) Successful in 5m2s
2026-11-07 02:38:28 +08:00
codex-bot 81cf7d9448 Add bounded public research HTTP contract and transport tests
Foundry Go checks / check (push) Successful in 2m54s
Foundry Go checks / check (pull_request) Successful in 2m55s
2026-11-07 01:58:30 +08:00
Zayden-Jung 2207c85ca6 Merge pull request 'Draft: 原子保存跨分区移动的最终坐标' (#16) from codex/member-drop-sync into main
Foundry Go checks / check (push) Successful in 5m42s
Deploy Foundry Core / deploy (push) Successful in 5m18s
Reviewed-on: Zayden-Jung/foundry-core#16
2026-11-06 14:50:02 +00:00
codex-bot 09c78d3ab8 Accept final member positions in ownership transactions
Foundry Go checks / check (push) Successful in 8m18s
Foundry Go checks / check (pull_request) Successful in 6m16s
2026-11-06 22:46:46 +08:00
Zayden-Jung b2ae48e250 Merge pull request '保留原图并提供单一预览,释放慢传输期间的空间锁' (#15) from codex/canvas-image-preview into main
Foundry Go checks / check (push) Successful in 3m23s
Deploy Foundry Core / deploy (push) Successful in 3m52s
Reviewed-on: Zayden-Jung/foundry-core#15
2026-11-06 13:55:30 +00:00
codex-bot 8abc79dc5b Keep a single preview variant and verify read lock boundaries
Foundry Go checks / check (push) Successful in 5m13s
Foundry Go checks / check (pull_request) Successful in 3m56s
2026-11-06 21:43:48 +08:00
codex-bot 67765c17f4 Add authenticated image previews and shorten canvas read locks
Foundry Go checks / check (push) Successful in 3m18s
2026-11-06 21:36:07 +08:00
Zayden-Jung 630ed42d53 Merge pull request '补齐真实子画布端口与外部连线原子创建接口' (#14) from codex/canvas-connections into main
Foundry Go checks / check (push) Successful in 6m16s
Deploy Foundry Core / deploy (push) Successful in 5m20s
Reviewed-on: Zayden-Jung/foundry-core#14
2026-11-06 11:39:53 +00:00
codex-bot 07fd678cf3 Add atomic connections across canvas subgraph boundaries
Foundry Go checks / check (push) Failing after 10m4s
Foundry Go checks / check (pull_request) Successful in 7m53s
2026-11-06 19:38:11 +08:00
Zayden-Jung 7e1bd538c1 Merge pull request '记录 Canvas V2 生产部署及指定测试画布迁移验收' (#13) from codex/canvas-v2-verification into main
Foundry Go checks / check (push) Successful in 2m47s
Reviewed-on: Zayden-Jung/foundry-core#13
2026-11-06 11:01:49 +00:00
codex-bot 56cd0c5715 Document Canvas V2 deployment and verified test-canvas migration
Foundry Go checks / check (push) Successful in 2m27s
Foundry Go checks / check (pull_request) Successful in 2m39s
2026-11-06 18:59:08 +08:00
Zayden-Jung b4e537b4ad Merge pull request '实现 Canvas V2:真实子画布、异步 AI 与受管图片资产' (#12) from codex/canvas-v2 into main
Foundry Go checks / check (push) Successful in 3m25s
Deploy Foundry Core / deploy (push) Successful in 3m19s
Reviewed-on: Zayden-Jung/foundry-core#12
2026-11-06 10:48:54 +00:00
codex-bot d6ee8942f1 Implement Canvas V2 subgraphs, assets and asynchronous AI execution
Foundry Go checks / check (push) Successful in 2m40s
Foundry Go checks / check (pull_request) Successful in 2m36s
2026-11-06 18:36:00 +08:00
Zayden-Jung 7847167043 Merge pull request '支持纯图片元素的 Canvas 快照格式' (#11) from codex/plain-images into main
Foundry Go checks / check (push) Successful in 2m52s
Deploy Foundry Core / deploy (push) Successful in 4m32s
Reviewed-on: Zayden-Jung/foundry-core#11
2026-11-06 04:44:26 +00:00
Zayden-Jung 867f0303d8 Merge pull request '将登录会话改为 30 天闲置续期与 90 天绝对期限' (#10) from codex/session-lifetime into main
Deploy Foundry Core / deploy (push) Has been cancelled
Foundry Go checks / check (push) Successful in 3m5s
Reviewed-on: Zayden-Jung/foundry-core#10
2026-11-06 04:44:18 +00:00
codex-bot 460b05f187 feat(canvas): support unframed image snapshot nodes
Foundry Go checks / check (push) Successful in 3m24s
Foundry Go checks / check (pull_request) Successful in 3m27s
2026-11-06 12:38:45 +08:00
codex-bot 34c461a61c feat(auth): renew sessions with 30-day idle and 90-day absolute limits
Foundry Go checks / check (push) Successful in 2m53s
Foundry Go checks / check (pull_request) Successful in 3m9s
2026-11-06 12:32:04 +08:00
Zayden-Jung 022086beb8 Merge pull request '支持 Canvas 框选区、成员归属与名称显示模式' (#9) from codex/canvas-frames into main
Foundry Go checks / check (push) Successful in 3m28s
Deploy Foundry Core / deploy (push) Successful in 3m4s
Reviewed-on: Zayden-Jung/foundry-core#9
2026-11-06 03:21:48 +00:00
codex-bot 6f504ebe15 Support canvas frame nodes and explicit membership snapshots
Foundry Go checks / check (push) Successful in 3m13s
Foundry Go checks / check (pull_request) Successful in 4m24s
2026-11-06 11:20:05 +08:00
Zayden-Jung 57aab71d45 Merge pull request 'Canvas 快照持久化与 workspace/board SEO slug' (#7) from codex/canvas-persistence into main
Foundry Go checks / check (push) Successful in 2m38s
Deploy Foundry Core / deploy (push) Successful in 3m45s
Foundry Go checks / check (pull_request) Successful in 3m20s
Reviewed-on: Zayden-Jung/foundry-core#7
2026-11-05 18:57:43 +00:00
codex-bot 6f36ef27bb Add versioned board canvas persistence and stable SEO slugs
Foundry Go checks / check (push) Successful in 7m30s
Foundry Go checks / check (pull_request) Successful in 8m43s
2026-11-06 02:47:27 +08:00
Zayden-Jung e8ed5e4f9f Merge pull request '修复 Google/Slack OAuth 回调的系统 CA 证书缺失' (#6) from codex/fix-oauth-ca into main
Foundry Go checks / check (push) Successful in 2m47s
Deploy Foundry Core / deploy (push) Successful in 2m30s
Reviewed-on: Zayden-Jung/foundry-core#6
2026-11-05 15:16:11 +00:00
codex-bot b1e0d783e6 Mount system CA roots for OAuth HTTPS requests
Foundry Go checks / check (push) Successful in 3m22s
Foundry Go checks / check (pull_request) Successful in 3m16s
2026-11-05 21:39:11 +08:00
Zayden-Jung 4043c89520 Merge pull request 'Foundry 用户认证、workspace 分享与结构化物料 API' (#5) from codex/foundry-platform into main
Foundry Go checks / check (push) Successful in 2m3s
Deploy Foundry Core / deploy (push) Successful in 2m15s
Reviewed-on: Zayden-Jung/foundry-core#5
2026-11-05 12:30:25 +00:00
codex-bot 155ce28c37 Report inconclusive Slack placeholder-code checks accurately
Foundry Go checks / check (push) Successful in 2m9s
Foundry Go checks / check (pull_request) Successful in 1m57s
2026-11-05 20:22:51 +08:00
codex-bot 6c69fcbaaa Inject Slack Actions secrets and verify live client credentials
Foundry Go checks / check (push) Failing after 1m37s
Foundry Go checks / check (pull_request) Successful in 2m3s
2026-11-05 20:19:49 +08:00
codex-bot 5b9af931c7 Wait for final PostgreSQL startup before migration checks
Foundry Go checks / check (push) Successful in 2m3s
Foundry Go checks / check (pull_request) Successful in 1m57s
2026-11-05 19:03:55 +08:00
codex-bot 9d5ab9e215 Fix shared OAuth exchange SQL by avoiding a reserved identifier
Foundry Go checks / check (push) Successful in 2m10s
Foundry Go checks / check (pull_request) Successful in 2m11s
2026-11-05 18:55:29 +08:00
codex-bot f69575d48f Serialize email verification and resend to preserve registration state
Foundry Go checks / check (push) Failing after 2m1s
Foundry Go checks / check (pull_request) Failing after 1m50s
2026-11-05 18:53:50 +08:00
codex-bot fbe0910638 Guard legacy Google accounts through provider login expansion
Foundry Go checks / check (push) Failing after 1m59s
Foundry Go checks / check (pull_request) Failing after 1m56s
2026-11-05 18:51:56 +08:00
codex-bot 5c0ad30a7a Add Slack OpenID login with verified identities and callback replay protection
Foundry Go checks / check (push) Failing after 2m2s
Foundry Go checks / check (pull_request) Failing after 2m4s
2026-11-05 18:49:41 +08:00
codex-bot 206cd45098 Apply tracked schema migrations before deployment and test runtime grants
Foundry Go checks / check (push) Successful in 1m48s
Foundry Go checks / check (pull_request) Failing after 1m38s
2026-11-05 18:43:45 +08:00
codex-bot 4a06944fec Verify multimodal content boundaries and every material sort
Foundry Go checks / check (push) Successful in 2m6s
Foundry Go checks / check (pull_request) Successful in 1m49s
2026-11-05 18:40:41 +08:00
codex-bot e0ba9c08e8 Expose paginated share redirect events to workspace admins
Foundry Go checks / check (push) Successful in 1m47s
Foundry Go checks / check (pull_request) Successful in 1m51s
2026-11-05 18:39:23 +08:00
codex-bot bfcea1b3af Add structured materials, canvas layouts, tags and content permissions
Foundry Go checks / check (push) Successful in 1m51s
Foundry Go checks / check (pull_request) Successful in 1m56s
2026-11-05 18:36:53 +08:00
codex-bot 0d0521f13d Implement verified email registration and queued TLS delivery
Foundry Go checks / check (push) Successful in 1m52s
Foundry Go checks / check (pull_request) Successful in 1m53s
2026-11-05 18:31:09 +08:00
codex-bot 1b756d36ce Add configurable onboarding and scoped invitation links
Foundry Go checks / check (push) Successful in 1m47s
Foundry Go checks / check (pull_request) Successful in 1m57s
2026-11-05 18:24:30 +08:00
codex-bot 53c4dbee8e Add workspace membership roles with serialized permission changes
Foundry Go checks / check (push) Successful in 1m38s
Foundry Go checks / check (pull_request) Successful in 1m43s
2026-11-05 18:19:19 +08:00
codex-bot e626a2359e Add authenticated profiles and prefill Google account names
Foundry Go checks / check (push) Successful in 1m42s
Foundry Go checks / check (pull_request) Successful in 1m51s
2026-11-05 18:17:44 +08:00
codex-bot 0fd84f0f6e Establish project-scoped account and collaboration schema
Foundry Go checks / check (push) Successful in 1m43s
Foundry Go checks / check (pull_request) Successful in 1m40s
2026-11-05 18:14:44 +08:00
Zayden-Jung c30a3cd197 Merge pull request '为 Foundry 添加项目级 Codex HTTP 接口' (#4) from codex/foundry-codex-http into main
Foundry Go checks / check (push) Successful in 1m27s
Deploy Foundry Core / deploy (push) Successful in 2m22s
Reviewed-on: Zayden-Jung/foundry-core#4
2026-11-05 07:33:05 +00:00
codex-bot 08aa0d69b6 Set worker directory ownership by numeric container UID
Foundry Go checks / check (push) Successful in 1m30s
Foundry Go checks / check (pull_request) Successful in 1m34s
2026-11-05 11:40:09 +08:00
codex-bot 81c2d2e6df Enforce the output limit on subprocess stdout copies
Foundry Go checks / check (push) Successful in 1m52s
Foundry Go checks / check (pull_request) Successful in 1m28s
2026-11-05 11:36:54 +08:00
codex-bot d80854deae Start the configured Codex worker during Foundry deployment 2026-11-05 11:36:46 +08:00
codex-bot 9e5d805f5a Add project-scoped Codex execution over a private socket
Foundry Go checks / check (push) Successful in 1m35s
Foundry Go checks / check (pull_request) Successful in 1m22s
2026-11-05 02:29:49 +08:00
Zayden-Jung 4d5e6e2512 Merge pull request '接受 Actions Variables 中格式化的项目回调 JSON' (#3) from codex/foundry-project-config into main
Foundry Go checks / check (push) Successful in 1m44s
Deploy Foundry Core / deploy (push) Successful in 2m18s
Reviewed-on: Zayden-Jung/foundry-core#3
2026-11-04 17:51:55 +00:00
codex-bot cc8ddba7aa Accept formatted Foundry project configuration from Actions
Foundry Go checks / check (pull_request) Successful in 1m21s
Foundry Go checks / check (push) Successful in 1m22s
2026-11-05 01:44:44 +08:00
Zayden-Jung c7ec5f7eb2 Merge pull request '部署检查只验证 Foundry 后端就绪' (#2) from codex/foundry-backend-smoke into main
Foundry Go checks / check (push) Successful in 1m23s
Deploy Foundry Core / deploy (push) Failing after 1m24s
Reviewed-on: Zayden-Jung/foundry-core#2
2026-11-04 17:03:24 +00:00
codex-bot 33719a549b Keep deployment smoke checks backend-only
Foundry Go checks / check (pull_request) Successful in 1m22s
Foundry Go checks / check (push) Successful in 1m21s
2026-11-05 00:57:53 +08:00
Zayden-Jung 17cec9ff06 Merge pull request '从 main 部署 Foundry Core 并注入 OAuth 配置' (#1) from codex/foundry-actions-deploy into main
Foundry Go checks / check (push) Successful in 1m23s
Deploy Foundry Core / deploy (push) Failing after 1m47s
Reviewed-on: Zayden-Jung/foundry-core#1
2026-11-04 16:48:52 +00:00
codex-bot 4e5832c14b Deploy Foundry Core from main with Actions credentials
Foundry Go checks / check (push) Successful in 1m30s
Foundry Go checks / check (pull_request) Has been cancelled
2026-11-05 00:19:19 +08:00
12 changed files with 17 additions and 535 deletions
-7
View File
@@ -1,7 +0,0 @@
PUBLIC_ORIGIN=https://api.example.com
DATABASE_URL=postgresql://foundry:replace-me@postgres.internal:5432/foundry_auth
GOOGLE_CLIENT_ID=replace-me.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=replace-me
FOUNDRY_PROJECTS='{"notes":"http://localhost:3000/auth/callback","board":"http://localhost:3001/auth/callback"}'
HOST=127.0.0.1
PORT=8080
-35
View File
@@ -1,35 +0,0 @@
name: Foundry Go checks
on: [push, pull_request]
jobs:
check:
runs-on: ces-control
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false
- name: Check formatting, test and build
run: |
set -eu
test -z "$(gofmt -l cmd internal)"
go test -mod=readonly ./...
go build -mod=readonly -o bin/foundry ./cmd/foundry
- name: Smoke test HTTP routes
env:
PUBLIC_ORIGIN: https://api.example.com
DATABASE_URL: postgres://foundry:fixture@127.0.0.1:5432/foundry
GOOGLE_CLIENT_ID: fixture
GOOGLE_CLIENT_SECRET: fixture
FOUNDRY_PROJECTS: '{"notes":"http://localhost:3000/auth/callback"}'
PORT: '18080'
run: |
set -eu
./bin/foundry &
server_pid=$!
trap 'kill "$server_pid" 2>/dev/null || true' EXIT
curl --silent --show-error --fail --retry 5 --retry-connrefused http://127.0.0.1:18080/healthz
status=$(curl --silent --show-error -o /dev/null -w '%{http_code}' http://127.0.0.1:18080/projects/notes/auth/me)
test "$status" = 401
+1 -2
View File
@@ -1,2 +1 @@
.env /target
/bin/
Generated
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "bedrock"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "bedrock"
version = "0.1.0"
edition = "2024"
[dependencies]
-24
View File
@@ -1,24 +0,0 @@
# 造物工坊 · Foundry Core
共享后端的第一版提供 Google 登录。各项目通过同一个 HTTPS API 登录,在私有 PostgreSQL 的认证库中维护独立账号和会话。项目业务库可分别配置独立的数据库和角色。
## 服务端配置
1. 在 Google Cloud 创建一个 Web application OAuth 客户端。授权重定向 URI 填写 `https://<API 域名>/auth/google/callback`。所有项目信任同一个客户端,因此共享 Google 同意页面的应用名称。
2. 在服务器私网准备 PostgreSQL 13 或以上版本。在认证库执行一次 `db/001-auth.sql`(使用 `psql -v ON_ERROR_STOP=1`),给运行账号授予这四张表所需的查询及增删改权限。
3. 按 `.env.example` 注入运行环境变量。每个项目配置一个固定的前端回调地址,本地开发可用 localhost。将 Google 客户端密钥和数据库连接串存入服务器的密钥管理设施。
4. 由 Gitea Actions 在 `ces-control` 上使用 Go 1.25 构建并检查。部署时运行 `foundry` 二进制,通过 HTTPS 反向代理转发至服务监听地址。通过 `GET /healthz` 检查进程,通过 `GET /readyz` 检查认证库。
5. 代理避免记录 Google 回调的查询参数及认证请求头。设置入口限流,并定时删除三张临时表(`oauth_attempts`、`login_grants`、`project_sessions`)中 `expires_at <= now()` 的记录。
## 前端接入
1. 在浏览器用 Web Crypto 生成 32 字节随机值,编码为无填充 Base64URL,作为 verifier 暂存在当前 tab 的 sessionStorage。对 verifier 字符串做 SHA-256 并用相同编码得到 challenge。
2. 顶层导航到 `GET /projects/<project>/auth/google?challenge=<challenge>`。Google 回到共享 API 后,API 将浏览器重定向至已配置的项目回调。
3. 回调页从 URL fragment 读取 `code` 或 `error`,用 history.replaceState 清掉 fragment。收到 code 时,向 `POST /projects/<project>/auth/exchange` 发送 `X-Foundry-Code` 和 `X-Foundry-Verifier` 请求头,随后清理暂存的 verifier。code 有效期一分钟,仅可使用一次。
4. 将返回的八小时会话凭证保存在内存中,使用 `Authorization: Bearer <access_token>` 调用 `GET /projects/<project>/auth/me`。通过 `POST /projects/<project>/auth/logout` 撤销会话并清理本地凭证。刷新页面后,内存凭证需要通过重新登录获取。
同一个 Google 账号首次进入不同项目时,会分别创建用户 ID。会话绑定其签发项目。Google 账号的标识 `sub` 用于认领同一项目的既有账号,邮箱只作为资料字段。当前注册模式为开放注册。
## 验收
用同一个 Google 测试账号分别登录两个项目,确认用户 ID 不同。用 A 的会话请求 B 的 `me` 应返回 401。验证兑换码重放被拒绝,并确认退出 A 后 B 的会话仍有效。
-54
View File
@@ -1,54 +0,0 @@
package main
import (
"encoding/json"
"log"
"net"
"net/http"
"net/url"
"os"
"time"
"gitea.entroia.com/Zayden-Jung/foundry-core/internal/auth"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/stdlib"
)
func env(key, fallback string) string {
if value := os.Getenv(key); value != "" {
return value
}
return fallback
}
func main() {
origin, err := url.Parse(os.Getenv("PUBLIC_ORIGIN"))
if err != nil || origin.Scheme != "https" || origin.Hostname() == "" || origin.User != nil ||
(origin.Path != "" && origin.Path != "/") || origin.RawQuery != "" || origin.Fragment != "" {
log.Fatal("PUBLIC_ORIGIN must be an HTTPS origin")
}
var callbacks map[string]string
if err := json.Unmarshal([]byte(os.Getenv("FOUNDRY_PROJECTS")), &callbacks); err != nil || len(callbacks) == 0 {
log.Fatal("FOUNDRY_PROJECTS must configure at least one project")
}
id, secret, dsn := os.Getenv("GOOGLE_CLIENT_ID"), os.Getenv("GOOGLE_CLIENT_SECRET"), os.Getenv("DATABASE_URL")
if id == "" || secret == "" || dsn == "" {
log.Fatal("Google credentials and DATABASE_URL are required")
}
config, err := pgx.ParseConfig(dsn)
if err != nil {
log.Fatal("Invalid DATABASE_URL")
}
db := stdlib.OpenDB(*config)
defer db.Close()
handler, err := auth.New(db, callbacks, origin.ResolveReference(&url.URL{Path: "/auth/google/callback"}).String(), id, secret)
if err != nil {
log.Fatal(err)
}
server := &http.Server{
Addr: net.JoinHostPort(env("HOST", "127.0.0.1"), env("PORT", "8080")),
Handler: handler, ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 10 * time.Second,
WriteTimeout: 30 * time.Second, IdleTimeout: 60 * time.Second,
}
log.Fatal(server.ListenAndServe())
}
-42
View File
@@ -1,42 +0,0 @@
BEGIN;
CREATE TABLE project_accounts (
project text NOT NULL,
id uuid NOT NULL,
google_subject text NOT NULL,
email text,
PRIMARY KEY (project, id),
UNIQUE (project, google_subject)
);
CREATE TABLE oauth_attempts (
state_hash text PRIMARY KEY,
browser_hash text NOT NULL,
project text NOT NULL,
frontend_challenge text NOT NULL,
google_verifier text NOT NULL,
expires_at timestamptz NOT NULL
);
CREATE TABLE login_grants (
token_hash text PRIMARY KEY,
project text NOT NULL,
account_id uuid NOT NULL,
frontend_challenge text NOT NULL,
expires_at timestamptz NOT NULL,
FOREIGN KEY (project, account_id) REFERENCES project_accounts (project, id) ON DELETE CASCADE
);
CREATE TABLE project_sessions (
token_hash text PRIMARY KEY,
project text NOT NULL,
account_id uuid NOT NULL,
expires_at timestamptz NOT NULL,
FOREIGN KEY (project, account_id) REFERENCES project_accounts (project, id) ON DELETE CASCADE
);
CREATE INDEX oauth_attempts_expiry ON oauth_attempts (expires_at);
CREATE INDEX login_grants_expiry ON login_grants (expires_at);
CREATE INDEX project_sessions_expiry ON project_sessions (expires_at);
COMMIT;
-14
View File
@@ -1,14 +0,0 @@
module gitea.entroia.com/Zayden-Jung/foundry-core
go 1.25.0
require github.com/jackc/pgx/v5 v5.7.6
require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/sync v0.13.0 // indirect
golang.org/x/text v0.24.0 // indirect
)
-28
View File
@@ -1,28 +0,0 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk=
github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-329
View File
@@ -1,329 +0,0 @@
package auth
import (
"context"
"crypto/rand"
"crypto/sha256"
"database/sql"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"log"
"net/http"
"net/url"
"regexp"
"strings"
"time"
)
var projectName = regexp.MustCompile(`^[a-z][a-z0-9-]*$`)
var tokenPattern = regexp.MustCompile(`^[A-Za-z0-9_-]{43}$`)
type service struct {
db *sql.DB
projects map[string]*url.URL
redirectURI, clientID, secret string
google *http.Client
}
func New(db *sql.DB, callbacks map[string]string, redirectURI, id, secret string) (http.Handler, error) {
s := &service{db: db, projects: make(map[string]*url.URL), redirectURI: redirectURI, clientID: id, secret: secret,
google: &http.Client{Timeout: 10 * time.Second, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}}
for name, raw := range callbacks {
u, err := url.Parse(raw)
if err != nil {
return nil, fmt.Errorf("invalid project callback for %q", name)
}
host := u.Hostname()
local := u.Scheme == "http" && (host == "localhost" || host == "127.0.0.1" || host == "::1")
if !projectName.MatchString(name) || host == "" || (u.Scheme != "https" && !local) || u.User != nil || u.Fragment != "" {
return nil, fmt.Errorf("invalid project callback for %q", name)
}
s.projects[name] = u
}
mux := http.NewServeMux()
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) { reply(w, 200, payload{"status": "ok"}) })
mux.HandleFunc("GET /readyz", s.wrap(func(w http.ResponseWriter, r *http.Request) error {
if _, err := s.db.ExecContext(r.Context(), "SELECT 1 FROM project_accounts LIMIT 1"); err != nil {
return err
}
reply(w, 200, payload{"status": "ready"})
return nil
}))
mux.HandleFunc("GET /auth/google/callback", s.wrap(s.callback))
mux.HandleFunc("/projects/{project}/auth/{action}", s.wrap(s.project))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
w.Header().Set("Referrer-Policy", "no-referrer")
ctx, cancel := context.WithTimeout(r.Context(), 25*time.Second)
defer cancel()
mux.ServeHTTP(w, r.WithContext(ctx))
}), nil
}
type payload map[string]any
func reply(w http.ResponseWriter, status int, body payload) {
if body != nil {
w.Header().Set("Content-Type", "application/json")
}
w.WriteHeader(status)
if body != nil {
_ = json.NewEncoder(w).Encode(body)
}
}
func reject(w http.ResponseWriter, status int, code string) error {
reply(w, status, payload{"error": code})
return nil
}
func (s *service) wrap(handle func(http.ResponseWriter, *http.Request) error) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if err := handle(w, r); err != nil {
log.Printf("request failed (%T)", err)
_ = reject(w, 503, "service_unavailable")
}
}
}
func token() string {
var value [32]byte
rand.Read(value[:])
return base64.RawURLEncoding.EncodeToString(value[:])
}
func digest(value string) string {
sum := sha256.Sum256([]byte(value))
return base64.RawURLEncoding.EncodeToString(sum[:])
}
func (s *service) project(w http.ResponseWriter, r *http.Request) error {
project, action := r.PathValue("project"), r.PathValue("action")
frontend := s.projects[project]
if frontend == nil {
return reject(w, 404, "not_found")
}
if r.Method == http.MethodGet && action == "google" {
return s.start(w, r, project)
}
w.Header().Set("Vary", "Origin")
if origin := r.Header.Get("Origin"); origin != "" {
if origin != frontend.Scheme+"://"+frontend.Host {
return reject(w, 403, "origin_denied")
}
w.Header().Set("Access-Control-Allow-Origin", origin)
}
switch {
case r.Method == http.MethodOptions:
w.Header().Set("Access-Control-Allow-Methods", "GET, POST")
w.Header().Set("Access-Control-Allow-Headers", "Authorization, X-Foundry-Code, X-Foundry-Verifier")
reply(w, 204, nil)
case r.Method == http.MethodPost && action == "exchange":
return s.exchange(w, r, project)
case r.Method == http.MethodGet && action == "me":
return s.account(w, r, project, false)
case r.Method == http.MethodPost && action == "logout":
return s.account(w, r, project, true)
default:
return reject(w, 405, "method_not_allowed")
}
return nil
}
func oauthCookie(state, value string, maxAge int) *http.Cookie {
return &http.Cookie{Name: "__Host-foundry-oauth-" + state, Value: value, Path: "/", MaxAge: maxAge,
Secure: true, HttpOnly: true, SameSite: http.SameSiteLaxMode}
}
func (s *service) start(w http.ResponseWriter, r *http.Request, project string) error {
challenge := r.URL.Query().Get("challenge")
if !tokenPattern.MatchString(challenge) {
return reject(w, 400, "invalid_challenge")
}
state, browser, verifier := token(), token(), token()
_, err := s.db.ExecContext(r.Context(), `
INSERT INTO oauth_attempts VALUES ($1, $2, $3, $4, $5, now() + interval '10 minutes')
`, digest(state), digest(browser), project, challenge, verifier)
if err != nil {
return err
}
query := url.Values{
"client_id": {s.clientID}, "redirect_uri": {s.redirectURI}, "response_type": {"code"},
"scope": {"openid email"}, "state": {state}, "code_challenge": {digest(verifier)},
"code_challenge_method": {"S256"}, "prompt": {"select_account"},
}
http.SetCookie(w, oauthCookie(state, browser, 600))
http.Redirect(w, r, "https://accounts.google.com/o/oauth2/v2/auth?"+query.Encode(), 302)
return nil
}
func (s *service) googleJSON(ctx context.Context, method, endpoint string, form url.Values, bearer string, result any) error {
var body io.Reader
if form != nil {
body = strings.NewReader(form.Encode())
}
req, err := http.NewRequestWithContext(ctx, method, endpoint, body)
if err != nil {
return err
}
if form != nil {
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
}
if bearer != "" {
req.Header.Set("Authorization", "Bearer "+bearer)
}
res, err := s.google.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != 200 {
return fmt.Errorf("Google returned HTTP %d", res.StatusCode)
}
return json.NewDecoder(io.LimitReader(res.Body, 1<<20)).Decode(result)
}
func (s *service) callback(w http.ResponseWriter, r *http.Request) error {
ctx := r.Context()
query := r.URL.Query()
state := query.Get("state")
if !tokenPattern.MatchString(state) {
return reject(w, 400, "invalid_state")
}
browser, err := r.Cookie(oauthCookie(state, "", 0).Name)
if err != nil || !tokenPattern.MatchString(browser.Value) {
return reject(w, 400, "invalid_state")
}
var project, challenge, verifier string
err = s.db.QueryRowContext(ctx, `
DELETE FROM oauth_attempts
WHERE state_hash = $1 AND browser_hash = $2 AND expires_at > now()
RETURNING project, frontend_challenge, google_verifier
`, digest(state), digest(browser.Value)).Scan(&project, &challenge, &verifier)
if errors.Is(err, sql.ErrNoRows) {
return reject(w, 400, "invalid_state")
}
if err != nil {
return err
}
frontend := s.projects[project]
if frontend == nil {
return reject(w, 400, "invalid_state")
}
http.SetCookie(w, oauthCookie(state, "", -1))
destination := *frontend
code := query.Get("code")
if code == "" || query.Has("error") {
destination.Fragment = "error=google_login_cancelled"
http.Redirect(w, r, destination.String(), 302)
return nil
}
var tokens struct {
AccessToken string `json:"access_token"`
}
err = s.googleJSON(ctx, "POST", "https://oauth2.googleapis.com/token", url.Values{
"code": {code}, "client_id": {s.clientID}, "client_secret": {s.secret}, "redirect_uri": {s.redirectURI},
"grant_type": {"authorization_code"}, "code_verifier": {verifier},
}, "", &tokens)
if err != nil {
return err
}
if tokens.AccessToken == "" {
return errors.New("missing Google access token")
}
var user struct {
Subject string `json:"sub"`
Email *string `json:"email"`
Verified bool `json:"email_verified"`
}
if err := s.googleJSON(ctx, "GET", "https://openidconnect.googleapis.com/v1/userinfo", nil, tokens.AccessToken, &user); err != nil {
return err
}
if user.Subject == "" {
return errors.New("missing Google subject")
}
if !user.Verified {
user.Email = nil
}
grant := token()
_, err = s.db.ExecContext(ctx, `
WITH account AS (
INSERT INTO project_accounts (project, id, google_subject, email) VALUES ($1, gen_random_uuid(), $2, $3)
ON CONFLICT (project, google_subject) DO UPDATE SET email = EXCLUDED.email
RETURNING id
)
INSERT INTO login_grants
SELECT $4, $1, id, $5, now() + interval '1 minute' FROM account
`, project, user.Subject, user.Email, digest(grant), challenge)
if err != nil {
return err
}
destination.Fragment = "code=" + grant
http.Redirect(w, r, destination.String(), 302)
return nil
}
func (s *service) exchange(w http.ResponseWriter, r *http.Request, project string) error {
code, verifier := r.Header.Get("X-Foundry-Code"), r.Header.Get("X-Foundry-Verifier")
if !tokenPattern.MatchString(code) || !tokenPattern.MatchString(verifier) {
return reject(w, 400, "invalid_exchange")
}
session := token()
result, err := s.db.ExecContext(r.Context(), `
WITH grant AS (
DELETE FROM login_grants
WHERE token_hash = $1 AND project = $2 AND frontend_challenge = $3 AND expires_at > now()
RETURNING account_id
)
INSERT INTO project_sessions
SELECT $4, $2, account_id, now() + interval '8 hours' FROM grant
`, digest(code), project, digest(verifier), digest(session))
if err != nil {
return err
}
count, err := result.RowsAffected()
if err != nil {
return err
}
if count == 0 {
return reject(w, 401, "invalid_grant")
}
reply(w, 200, payload{"access_token": session, "token_type": "Bearer", "expires_in": 28800})
return nil
}
func (s *service) account(w http.ResponseWriter, r *http.Request, project string, logout bool) error {
token, ok := strings.CutPrefix(r.Header.Get("Authorization"), "Bearer ")
if !ok || !tokenPattern.MatchString(token) {
return reject(w, 401, "invalid_session")
}
if logout {
_, err := s.db.ExecContext(r.Context(), "DELETE FROM project_sessions WHERE token_hash = $1 AND project = $2", digest(token), project)
if err != nil {
return err
}
reply(w, 204, nil)
return nil
}
var id string
var email *string
err := s.db.QueryRowContext(r.Context(), `
SELECT a.id::text, a.email FROM project_sessions s
JOIN project_accounts a ON a.project = s.project AND a.id = s.account_id
WHERE s.token_hash = $1 AND s.project = $2 AND s.expires_at > now()
`, digest(token), project).Scan(&id, &email)
if errors.Is(err, sql.ErrNoRows) {
return reject(w, 401, "invalid_session")
}
if err != nil {
return err
}
reply(w, 200, payload{"project": project, "id": id, "email": email})
return nil
}
+3
View File
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}