Skip to content

Commit 87d2f1c

Browse files
committed
docs(auth): withdraw review nits; pin the admin withdraw's audit credit
- connect-mcp: the admin withdraw refuses no session 401, anyone else 403. - Test prose no longer calls better-auth's delete-consent the Console's. - dogfood: the admin door's generic delete row is credited to the administrator who withdrew the grant. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibxU7nr4BXM7e8qMfwq
1 parent 7123f12 commit 87d2f1c

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎content/docs/ai/connect-mcp.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ drive this MCP server. Same word, different layer.
387387
nothing. A platform administrator does the same for a person with
388388
`GET /api/v1/auth/admin/authorized-clients?userId=…` and
389389
`POST /api/v1/auth/admin/authorized-clients/withdraw` with
390-
`{ "userId": "…", "id": "…" }`; anyone else is refused `403`. The SDK
390+
`{ "userId": "…", "id": "…" }`; a request with no session is refused
391+
`401`, and anyone else who is signed in is refused `403`. The SDK
391392
spells them `oauth.authorizedClients.list()` / `withdraw(id)` and
392393
`listForUser(userId)` / `withdrawForUser(userId, id)`.
393394
- **Action bodies run as trusted app code** once invoked (the `ai.exposed`

‎packages/plugins/plugin-auth/src/mcp-client-last-use.real-engine.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ async function rig() {
178178
return value == null || value === '' ? null : new Date(value).toISOString();
179179
};
180180

181-
/** The person withdraws a consent: the row is deleted, as `/oauth2/delete-consent` and `/oauth2/revoke` delete it. */
181+
/** The person withdraws a consent: the row is deleted, as `/oauth2/revoke`, the authorized-clients withdraw and better-auth's own `/oauth2/delete-consent` delete it. */
182182
const withdraw = async (consentId: string): Promise<void> => {
183183
const ctx = await manager.getAuthContext();
184184
await ctx.adapter.delete({ model: 'oauthConsent', where: [{ field: 'id', value: consentId }] });

‎packages/plugins/plugin-auth/src/mcp-token-revocation.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
* `verifyMcpAccessToken` — which the MCP route answers with a 401
2121
* (`@objectstack/runtime` `http-dispatcher.mcp-oauth.test.ts`, "invalid /
2222
* expired JWT bearer → 401", pins that a refused bearer is a 401 there);
23-
* - the Console's `delete-consent` refuses the same bearer, with no extra write;
23+
* - better-auth's own `delete-consent` (which the Console does not call; it
24+
* withdraws through `authorized-clients-withdraw.ts`) refuses the same
25+
* bearer, with no extra write;
2426
* - a revoke sent by ANOTHER client answers 200 and the owner's token works;
2527
* - a `token_type_hint` naming another token type does not end the search
2628
* (RFC 7009 §2.1): the MCP access token is revoked all the same;
@@ -250,7 +252,7 @@ describe('[ruling A] /oauth2/revoke revokes an MCP access token through its cons
250252
expect(await r.rowsAtRest('sys_oauth_consent')).toHaveLength(1);
251253
}, 60_000);
252254

253-
it('the Console\'s `delete-consent` refuses the same bearer on the next request, with no extra write', async () => {
255+
it('better-auth\'s own `delete-consent` refuses the same bearer on the next request, with no extra write', async () => {
254256
const r = await rig();
255257
const { clientId, cookie, access_token } = await r.connect();
256258
const listed = await r.send(new Request(`${AUTH}/oauth2/get-consents`, { headers: { cookie } }));

‎packages/qa/dogfood/test/authorized-client-withdraw.dogfood.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
* Each withdraw deletes the consent through better-auth's own adapter, so
2121
* plugin-audit's generic writer records it exactly as it records the grant:
2222
* a `create` row when the consent page writes the consent, a `delete` row when
23-
* the withdraw removes it, credited to the person who withdrew it. The access
23+
* the withdraw removes it, credited to whoever withdrew it (the person on the
24+
* own door, the administrator on the admin door). The access
2425
* matrix (unknown ids, foreign keys, every non-admin caller) is pinned on the
2526
* real plugin in `plugin-auth` `authorized-clients-read.real-plugin.test.ts`.
2627
*/
@@ -247,5 +248,13 @@ describe('#31048 withdrawing an authorized AI assistant refuses its token on the
247248
expect(await consentRows(id)).toEqual([]);
248249
const refused = await initialize(grant.accessToken);
249250
expect(refused.status, await refused.clone().text()).toBe(401);
251+
252+
const adminMe = await stack.apiAs(adminToken, 'GET', '/auth/get-session');
253+
const adminId = String(((await adminMe.json()) as any)?.user?.id ?? '');
254+
expect(adminId).not.toBe('');
255+
expect(adminId).not.toBe(ownerId);
256+
const deletes = await auditRowsFor(id, 'delete');
257+
expect(deletes, 'the admin withdraw is audited as the own one is: a generic delete row').toHaveLength(1);
258+
expect(deletes[0].user_id, 'credited to the administrator who withdrew it, not the person').toBe(adminId);
250259
});
251260
});

0 commit comments

Comments
 (0)