Repository navigation
feat(subscription): bind an OAuth channel account to a user subscription (HQ-Task T261105-02) - #3
Merged
Conversation
…ion (HQ-Task T261105-02) An administrator can bind one Claude Subscription (OAuth) (type 64) or ChatGPT Subscription (Codex) (type 57) channel to an active user subscription, change or release the binding, or bind while creating the subscription. Binding moves the channel into a dedicated group `oauth-ch<channelId>` (abilities rebuilt, previous group remembered) and switches the user to that group through the existing UpgradeGroup / PrevUserGroup snapshot, so expiry, invalidate and delete restore the user with the unchanged downgrade logic. Invalidate, delete and unbind also return the channel to its previous group; an expired subscription keeps the channel parked in its private group until an administrator rebinds or unbinds it. One channel can be bound to one active subscription at a time; the group ratio for the dedicated group is provisioned automatically and the group is never added to UserUsableGroups, so only the owner can select it. Auto tokens of a bound user resolve to the dedicated group only. Subscribers see the bound account's 5-hour / 7-day (Claude) or primary / secondary (Codex) windows on the wallet subscription card through GET /api/subscription/self/usage/:id, which checks ownership and returns only window utilization and reset times. Reset credits stay on the administrator channel endpoints. The admin user-subscription drawer shows the bound account and opens the existing channel usage dialogs. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This was referenced Nov 6, 2026
Merged
Merged
Merged
1 of 5 tasks
AdoreJc
added a commit
that referenced
this pull request
Nov 14, 2026
请求路径不持锁读取、选项同步整体替换,改用 atomic.Pointer 并提供 AlternateServerAddresses / SetAlternateServerAddresses / IsAlternateServerAddress。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
AdoreJc
added a commit
that referenced
this pull request
Nov 14, 2026
* feat(system): 多站点地址访问控制台 (HQ-Task T261113-11) 新增选项 AlternateServerAddresses,同一部署可通过多个站点地址打开控制台。 给浏览器的链接跟随用户进来的线路:OAuth redirect_uri(流程开始时记录, 回调换 token 时复用)、密码重置邮件链接、支付完成后的回跳页、/api/status 的 server_address。Origin / Referer / Host 只在已配置地址中做精确匹配, 匹配不上一律回落 ServerAddress;已配置的 HTTPS 地址同时被会话 cookie 的 origin 检查信任。 移植自 71491b3cb,并覆盖其后新增的回跳点:Stripe 支付宝/微信充值、 订阅 Stripe 订阅与一次性 Checkout、订阅 Epay 的浏览器回跳。支付平台 异步通知地址与邮件 OAuth 的 redirect URI 仍使用 ServerAddress。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * test(system): 订阅 Epay 回跳测试并入 return_path_test.go,避免与 PR #21 的测试文件冲突 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * test(web): 站点信息表单测试夹具补 AlternateServerAddresses Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * refactor(system): 备用站点地址列表改为原子读写 (HQ-Review R1 #3) 请求路径不持锁读取、选项同步整体替换,改用 atomic.Pointer 并提供 AlternateServerAddresses / SetAlternateServerAddresses / IsAlternateServerAddress。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HQ-Task: T261105-02
Agent
Links
hq/tasks/briefs/T261105-02.md)User request
Out of scope — refuse
fork-main; the Codex/Claude OAuth channel types already live only in this fork)Open gate — do not open unless all are satisfied
go buildor tests passed: yesKind
Issue facts
user_subscriptions); relay unchanged except Auto-group resolution; billing untouched.Change
Design
model/subscription.go,model/subscription_channel_binding.go):UserSubscriptiongainsbound_channel_id,bound_group,bound_channel_prev_group,bound_prev_upgrade_group(plus non-storedbound_channel_type/name/statusprojections). Binding is only allowed on an active subscription and only for channel types 64 (Claude OAuth) / 57 (Codex), single-key.grouptooauth-ch<channelId>(abilities rebuilt in the same transaction, the previous group string is remembered), switches the user to that group and writes it intoUpgradeGroup(snapshotting the plan's upgrade group inbound_prev_upgrade_group, andPrevUserGroupif it was empty). Because the dedicated group lives inUpgradeGroup, the existing expiry (ExpireDueSubscriptions), invalidate and delete paths restore the user's group without modification.service.GetRequestAutoGroupspins Auto tokens of a user whose group is a binding group to that group only (no fallback to shared pools; empty list when the group has no ratio). The group ratio is provisioned viaUpdateOption("GroupRatio")(copied from the user's group, else 1). The group is deliberately not added toUserUsableGroups: the owner can use it because it is their own group; nobody else can select it.bound_channel_id+ active +end_time > now). Ended subscriptions that still reference the channel are detached when it is rebound.GET /api/subscription/admin/bindable_channels,POST /api/subscription/admin/user_subscriptions/:id/bind_channel,POST .../unbind_channel;POST /api/subscription/admin/users/:id/subscriptionsaccepts an optionalchannel_id(create + bind in one transaction). Audit actionssubscription.channel_bind/subscription.channel_unbind.GET /api/subscription/self/usage/:idchecks ownership and activity, then returns{provider, channel_type, windows{...utilization, resets_at, window_seconds}, plan_type, limit_reached}. Claude:five_hour,seven_day,seven_day_sonnet,seven_day_overage_includedfrom/api/oauth/usage; Codex:primary,secondaryfrom/backend-api/wham/usage. Email, user id, organization, extra-usage and reset-credit data are dropped; upstream errors return only the status code. Reset credits remain on the admin channel endpoints. The channel key / token refresh-and-retry logic ofcontroller/claude_usage.goandcontroller/codex_usage.gowas extracted intoclaudeChannelOAuthFetch/codexChannelWhamFetchand reused.user-subscriptions-dialog.tsx) gets an optional channel picker when adding a subscription, a "Bound account" column, Bind/Change/Unbind actions (bind-channel-dialog.tsx, which warns which group the channel leaves) and "View account usage" that opens the existingClaudeUsageDialog/CodexUsageDialog(reset stays admin-only there). Wallet card shows the bound account kind and group with "View account usage" →subscription-usage-dialog.tsx(reusesUsageWindowCard). 34 keys added to all 7 locale files (text insertion;bun run i18n:syncis a no-op afterwards).model/db_time.go:getDBTimestampTxsoCreateUserSubscriptionFromPlanTxreads the DB clock through the open transaction (needed for single-connection SQLite tests; same SQL otherwise).Research
Duplicate / prior art
UpgradeGroup/PrevUserGroup/DowngradeGroupgroup transitions and the admin channel usage endpoints existed; this PR composes them.Docs and code
AGENTS.md,web/AGENTS.md.model/subscription.go(group snapshot and expiry),model/ability.go(UpdateAbilitieskeyed bygroup|model),middleware/auth.go+service/group.go+service/channel_select.go(group resolution: user group → using group; Auto list),controller/claude_usage.go/codex_usage.go(usage fetch with refresh),middleware/access_token_routes.go(every panel route must declare a scope).Alternatives considered
UpgradeGroupuntouched and add a separate restore path — rejected: duplicates the expiry/invalidate/delete logic.oauth-ch<id>).Files
Behavior
default) are unchanged and still use the shared pools (documented in the bind dialog).Verification
GOWORK=off go build ./...→ ok;GOWORK=off go vet ./model/ ./controller/ ./service/ ./router/→ clean;gofmt -l→ clean.GOWORK=off go test ./model/ -run 'Binding|BoundGroup|Subscription'→ ok (8 new tests: bind/rebind/unbind, plan-upgrade-group restore, invalidate/delete release, expiry keeps channel parked + rebind detaches, create+bind rollback, uniqueness, group names).GOWORK=off go test ./controller/ -run 'SubscriptionSelfUsage|Claude|Codex'→ ok (foreign/missing/expired/unbound/dangling subscription rejected; Claude and Codex projections drop email/org/credits; upstream 403 returns status only).GOWORK=off go test ./service/ -run AutoGroups→ ok (pinned Auto groups);GOWORK=off go test ./router/ -run TestAccessTokenRouteRulesCoverEveryDashboardRoute→ ok.GOWORK=off go test ./model/ ./controller/ ./service/ ./router/ ./middleware/: model ok, service ok, router ok; controller and middleware fail only with the pre-existing WindowsTempDir RemoveAll cleanup: ... audit.db / oneapi-*.log: The process cannot access the fileerrors (no assertion failures; same on fork-main).relaykit/,tokenkit/:GOWORK=off go build ./...→ ok.tsgo -b→ clean;oxlinton touched files → clean (2 pre-existing errors in untouchedsubscriptions/constants.ts,subscriptions-provider.tsx);oxfmt --check→ clean;bun run test→ 208 files / 2500 tests pass (incl. 7 new);bun run build→ ok;bun run i18n:sync→ no diff after inserting 34 keys × 7 locales.new-api-fork:t261105-02built from d225925, containernew-api-t05:39683, SQLite,/api/status200, "ready in 1133 ms", no panic in logs):default,vip), channel chore: merge upstream main (72f3dc7da) into fork-main #2 type 57 (fake token, groupdefault); normal user t05user (groupdefault).#1 t05-claude-oauth-fake · Claude 订阅(OAuth) · 分组: default,vip; 新增订阅 → toast "用户分组将切换为 oauth-ch1"; user list shows t05user groupoauth-ch1; drawer column 绑定账户 shows#1 t05-claude-oauth-fake / Claude 订阅(OAuth) · oauth-ch1. API state: channel feat(channel): Claude Subscription (OAuth) channel with usage and reset credits; Codex browser OAuth flow #1 groupoauth-ch1, GroupRatio gainedoauth-ch1:1, UserUsableGroups unchanged, subscriptionupgrade_group=oauth-ch1 prev_user_group=default bound_channel_prev_group=default,vip.HTTP 401badge and "上游返回状态码 401" (error path; no real token used).default, channel feat(channel): Claude Subscription (OAuth) channel with usage and reset credits; Codex browser OAuth flow #1 groupdefault,vip, binding cleared, subscription still active.oauth-ch2; create+bind for another user with channel chore: merge upstream main (72f3dc7da) into fork-main #2 → "This channel is already bound to another active subscription" and no subscription row created; Codex admin usage → upstream 401; invalidate → "User group will be reverted to default", userdefault, channel chore: merge upstream main (72f3dc7da) into fork-main #2 groupdefault, subscriptioncancelledwithbound_channel_id=0.model/subscription_channel_binding_test.go,controller/subscription_binding_test.go,service/group_auto_groups_test.go(+1 case),web/src/features/subscriptions/__tests__/channel-binding.test.ts,web/src/features/subscriptions/__tests__/subscription-usage-dialog.test.tsx.postgres:17-alpine+ the new image, fresh AutoMigrate:bound_channel_id bigint,bound_group/bound_channel_prev_group/bound_prev_upgrade_group varchar(64), indexidx_user_subscriptions_bound_channel_id; restart → "ready",/api/status200). Providers: none (fake tokens, upstream 401 paths only).docker pullfails there with the Docker Desktop credential-helper error over SSH); upgrade of a database created by the latest release (only fresh DBs); real Claude/Codex usage responses; relay traffic through the dedicated group (no real account); log-rotation and audit.db tests on Windows (pre-existing environment failures).Risks
oauth-ch<id>by hand ends pinning for that user (release logic then leaves the channel alone); a user whose tokens are pinned to another group bypasses the bound account (documented).AdminAuth; access-token scopeswallet:read/billing:read/billing:write.Scope check
🤖 Generated with Claude Code