You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9f61e06
Browse filesBrowse the repository at this point in the historyBrowse files
fix(plugin-auth): withdrawing an AI assistant in one organization keeps its refresh tokens in the person's other organizations (#31132)
<!-- claude-projects-attribution: {"github_login":"marchtian"} -->
_Requested by **田騏** · [project
thread](https://claude.ai/code/project/chan_01VmuUhXU9SSUzqJYyXSmYSi?thread=cmsg_01VmuUhXU9SSUzqJYyXSmYSi9Hju7DThD7eoLKoJU9hnHj)_Fixes#31076
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么**:撤回 AI 助手(控制台的两个撤回入口和
`/oauth2/revoke`)时,只删除该组织下签发的刷新令牌,以及没有记录组织的旧刷新令牌;其他组织的刷新令牌保留。
- **为什么改**:同一个人在两个组织里授权了同一个助手,在 A 组织撤回后,B 组织里的助手也会在访问令牌过期后被登出,只能重新授权。
-
**风险与回滚**:失败方向是"多删"而不是"少删":撤回组织的每一行刷新令牌(含已轮换的和并发轮换出的新行)都删,没有组织的行在任何撤回时也都删。回滚即
revert 本 PR,行为回到按客户端+用户整族删除。
- **先看**:`packages/plugins/plugin-auth/src/mcp-token-revocation.ts` 的
`isRefreshFamilyRow` 与
`revokeMcpGrant`(两轮读删);`mcp-token-revocation.test.ts` 末尾新增的 describe。
- **两分钟验证**:`pnpm --filter @objectstack/plugin-auth exec vitest run
src/mcp-token-revocation.test.ts`,预期 17 条全绿,其中 4 条是新增的两组织用例。
- **需要你做的**:无,席位落地。
## What changes
- `revokeMcpGrant` (shared by `/oauth2/revoke` and both console
withdraws, `POST /api/v1/auth/authorized-clients/withdraw` and the admin
door) no longer reads the refresh family by client + user alone. A
refresh row stores the organization it was minted under (`referenceId` /
`reference_id`, measured on the installed `@better-auth/oauth-provider`
1.7.12: the consent's reference is copied onto the authorization code,
the refresh token it starts, and every rotation, since
`handleRefreshTokenGrant` passes `refreshToken.referenceId` to
`createUserTokens`).
- The family a revoke deletes is: client + user AND (the row's reference
is the grant's organization, by the consent rule `isConsentFor`, OR the
row has no reference). Only a row that names ANOTHER organization is
kept.
- A row with no reference dies on every revoke of that client for that
person, as before this change. Which grant it was minted under cannot be
read off it (a row from before consents bound an organization, or from
any path that leaves the reference unset, looks the same), so keeping it
could leave the withdrawn assistant a live refresh token. This is the
seat's ruling on the claim thread: fail closed.
- The family is deleted by id in two read-and-delete passes. A rotation
racing the first pass started from a row that pass read and wrote its
successor after the read. The second read finds that successor. The
provider's own filter delete catches a successor written before the
delete runs, and the second read runs later than that, so no revoke
deletes less than before.
- `/oauth2/revoke` answers exactly as before (RFC 7009 revoke of one
token).
- Changeset: `@objectstack/plugin-auth` patch.
## Tests
On the real plugin (`AuthManager` + `@better-auth/oauth-provider` 1.7.12
+ `ObjectQL` over `driver-sql`/better-sqlite3), one person and one DCR
public client, consents in organizations A and B
(`mcp-token-revocation.test.ts`, new describe "a grant is revoked in its
own organization only"):
1. `/oauth2/revoke` of A's access token: A's consent and refresh row are
gone, A's bearer is refused and its refresh token mints nothing; B's
bearer still verifies with `organizationId` B, and B's refresh token
refreshes into a token that verifies in B.
2. The shared function, as the console withdraws call it: after one
rotation of A (a rotated row and its live successor), revoking A deletes
both and nothing of B. CONTROL: revoking the remaining organization
leaves no refresh row and no consent at all.
3. A refresh row with no organization (consented with no active
organization) dies on an A withdraw and mints nothing afterwards; B
still refreshes.
4. A rotation of A performed between the revoke's family read and its
delete: its successor is deleted too and mints nothing.
The withdraw doors' own suite
(`authorized-clients-read.real-plugin.test.ts`) seeds token rows through
a fixture that wrote them with no `reference_id` under consents bound to
an organization, a shape the provider never writes. The fixture now
writes the consent's reference on both token rows, as the provider does.
No assertion changed.
## Acceptance notes
- **File surface:** the claim names `mcp-token-revocation.ts` and its
tests. `authorized-clients-read.real-plugin.test.ts` is also touched
(fixture only, see Tests). The seat accepted it as a declared deviation.
- **Known nuisance kept:** a person who also has a no-organization grant
of the same client loses that grant's refresh token when they withdraw
the client in an organization. That is today's behaviour for those rows
and is the cost of failing closed on rows whose grant cannot be
identified.
- The header of `authorized-clients-withdraw.ts` still says the withdraw
deletes "the client's refresh family for that person". It is now that
family minus other organizations' rows. That file is outside the claimed
surface, so it is left unchanged and named here.
## Verification
All at head `aa7a88d0ea`, worktree on origin/main `5f0037449`.
<details><summary>Targeted tests</summary>
- `pnpm exec vitest run src/mcp-token-revocation.test.ts
src/authorized-clients-read.real-plugin.test.ts` (plugin-auth): Test
Files 2 passed, Tests 35 passed.
- `pnpm --filter @objectstack/plugin-auth exec vitest run`: before the
fixture fix, 2 failed (the two withdraw-door tests named above) | 4191
passed | 10 skipped; full package rerun after the fix at aa7a88d:
Test Files 232 passed (232), Tests 4193 passed | 10 skipped (4203).
- `pnpm --filter @objectstack/plugin-auth build && pnpm --filter
@objectstack/plugin-auth typecheck`: exit 0 (`check:test-typecheck:
OK`).
- `eslint --no-inline-config` on the two touched source/test files: exit
0.
</details>
<details><summary>Ablations (scripts/ablation-replace.mjs, each restored
to the HEAD blob with git diff HEAD empty)</summary>
- **Scoping removed** (`isRefreshFamilyRow` answers `true`, the old
client + user family): 4 of the new tests red, e.g. `expected [] to
deeply equal [ 'B_ORG_ID' ]` (B's row deleted).
- **No-reference rule removed** (`isRefreshFamilyRow` answers
`isConsentFor` only): test 3 red, `the row with no organization went
with A: expected [ '(none)', … ] to deeply equal [ … ]`.
- **One pass** (`REFRESH_FAMILY_PASSES = 1`): test 4 red, `its successor
was deleted too: expected [ …(2) ] to deeply equal [ … ]`.
</details>
<details><summary>Gates</summary>
Local subset, every command derived by `node
scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` for this diff, run at aa7a88d (exit code
captured before any pipe):
```text
node scripts/check-adr-0087-registration.mjs --base origin/main :: exit 0
node scripts/check-adr-0087-registration.mjs --self-test :: exit 0
node scripts/check-changeset-no-major.mjs --base origin/main :: exit 0
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-adoption.mjs :: exit 0
node scripts/check-comment-mask-adoption.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/check-dev-prereqs.mjs --self-test :: exit 0
node scripts/check-dts-emitted.mjs --self-test :: exit 0
node scripts/check-empty-changeset.mjs --base origin/main :: exit 0
node scripts/check-empty-changeset.mjs --self-test :: exit 0
node scripts/check-issue-citations.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs :: exit 0
node scripts/check-plugin-teardown-shape.mjs --self-test :: exit 0
node scripts/check-tenant-audit-census.mjs :: exit 0
node scripts/check-tenant-audit-census.mjs --self-test :: exit 0
node scripts/ci/assert-turbo-remote-cache.mjs --self-test :: exit 0
node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0
node scripts/ci/prune-turbo-cache.mjs --self-test :: exit 0
node scripts/ci/snapshot-next.mjs --self-test :: exit 0
node scripts/docs-audit/check-affected-docs.mjs :: exit 0
node scripts/docs-audit/check-drift-comment.mjs :: exit 0
node scripts/pm/release-rehearsal-clone.mjs --self-test :: exit 0
node scripts/release-pending-publish.mjs --self-test :: exit 0
pnpm --filter @objectstack/spec run check:duration-unit-keys :: exit 0
pnpm check:changeset-gate-self-tests :: exit 0
pnpm check:ci-filter-parity :: exit 0
pnpm check:closed-ceremony-text :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:doc-authoring :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:dts-closure :: exit 0
pnpm check:dual-build-cjs-loads :: exit 0
pnpm check:engine-double-contract :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:issue-citations :: exit 0
pnpm check:keyed-text-bounds :: exit 0
pnpm check:lean-entry-closure :: exit 0
pnpm check:logger-receiver-detach :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:objectql-double-limit :: exit 0
pnpm check:org-identifier :: exit 0
pnpm check:page-declaration-shape :: exit 0
pnpm check:platform-object-tenancy-census :: exit 0
pnpm check:published-files :: exit 0
pnpm check:query-options-erasure :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:registry-log-declared :: exit 0
pnpm check:rest-log-spy-declared :: exit 0
pnpm check:slot-lookup :: exit 0
pnpm check:sourcemap-no-sources-content :: exit 0
pnpm check:system-context-census :: exit 0
pnpm check:test-source-alias :: exit 0
pnpm check:tier-file-adoption :: exit 0
pnpm check:type-check-coverage :: exit 0
pnpm check:type-check-debt :: exit 0
pnpm check:undeclared-dep-imports :: exit 0
pnpm check:vouch-for-reference-callers :: exit 0
pnpm check:watch-hint-literal :: exit 0
pnpm check:where-matcher :: exit 0
```
`dispatch-gates --ran`: 61 derived famil(ies) accounted for — 61 run, 0
NOT-MEASURED. Every family CI runs is read from this PR's check-runs.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(plugin-auth): withdrawing an AI assistant in one organization no longer signs it out of the person's other organizations
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
A person can authorize the same AI assistant (an OAuth client such as Claude Desktop) in two organizations. Withdrawing it in one of them, from the console (`POST /api/v1/auth/authorized-clients/withdraw` or the admin door) or with `POST /oauth2/revoke`, deleted only that organization's consent but every refresh token the assistant held for that person, in every organization. The assistant then stopped working in the other organization once its access token expired, and the person had to authorize it there again. A withdraw now deletes the refresh tokens minted in the withdrawn organization only: every one of them, rotated or live, and the access tokens minted from them. The other organization's refresh token keeps refreshing. A refresh token minted with no active organization belongs to the grant with no organization and is deleted when that grant is withdrawn. `/oauth2/revoke` answers exactly as before.
0 commit comments