Skip to content

Commit 2003bd1

Browse files
committed
feat(plugin-auth): read the AI assistants a person has authorized, with a coarse last-use stamp
Two ObjectStack reads under the auth route: the caller's own OAuth consents, keyed by the session alone with a closed empty query set, and another person's for a platform administrator, gated as the admin session doors are. Each row carries the consent id, client id and name, scopes, organization, authorized-at and last-used-at, and no token material. The last-use stamp is sys_oauth_consent.last_used_at: written server-side after an MCP access token verifies, off the request path, at most once per consent per hour, with the hour's start. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4d1LNDAUs8pz7DNjQFC
1 parent a0ec7b1 commit 2003bd1

13 files changed

Lines changed: 987 additions & 8 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/client': patch
3+
---
4+
5+
feat(client): `client.oauth.authorizedClients.list()` and `.listForUser(userId)` read the AI assistants a person has authorized and when each was last used
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
`list()` calls `GET /api/v1/auth/authorized-clients` with no parameter: the caller's own grants. `listForUser(userId)` calls `GET /api/v1/auth/admin/authorized-clients?userId=...` and is answered for a platform administrator only. Both unwrap the `{ success, data }` envelope to the new exported `AuthorizedClientsList` type, `{ clients: AuthorizedClient[]; truncated: boolean }`. `AuthorizedClient.lastUsedAt` is an hour start, `null` when no use has been recorded. A refusal throws, as every other method does. Nothing existing changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/platform-objects': patch
3+
---
4+
5+
feat(platform-objects): `sys_oauth_consent` gains `last_used_at`, the start of the most recent hour in which the client made a verified MCP call under the consent
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
A nullable, read-only datetime on the better-auth-managed consent table, owned by ObjectStack. The OAuth provider neither reads nor writes it. Its one writer is plugin-auth, server-side, after it verifies an MCP access token minted under the consent. The object stays off the data API (`apiEnabled: false`), so no client reaches the column. A withdrawn or revoked consent takes the stamp with it. Schema sync adds the column, and existing rows read `null`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
---
4+
5+
feat(plugin-auth): a person can read the AI assistants they have authorized and when each was last used, and a platform administrator can read another person's
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: none
9+
10+
Two new reads, both ObjectStack mounts ahead of the better-auth catch-all and both in `AUTH_ROUTE_LEDGER`:
11+
12+
- `GET /api/v1/auth/authorized-clients` answers the signed-in person's own OAuth consents (Claude Desktop, an IDE agent, any MCP client). It is keyed by the session and nothing else: it takes no query parameter, and one that is sent (`?userId=` included) is refused `400 VALIDATION_ERROR` rather than ignored.
13+
- `GET /api/v1/auth/admin/authorized-clients?userId=ID` answers another person's, for a platform administrator only. It is gated exactly as the admin session doors are (ADR-0068 D2, a held session refused per ADR-0069 D3). The gate runs before the query is read, so anyone else (an organization owner or admin included) gets one `403 PERMISSION_DENIED` whether or not the person exists. It lists every organization the person granted in. A missing, empty or repeated `userId` is `400`, and an id naming no user is `404 RESOURCE_NOT_FOUND`. It is read only.
14+
15+
Each row carries exactly `id` (the consent id, the key `POST /oauth2/delete-consent` takes), `clientId`, `name`, `scopes`, `organizationId`, `authorizedAt` and `lastUsedAt`. Nothing in it identifies or reconstructs a token. The answer is newest first, at most 200 rows, with `truncated: true` when the person holds more, and it is sent with `Cache-Control: no-store`.
16+
17+
`lastUsedAt` is the start of the most recent clock hour in which the client made a verified MCP call under that consent, or `null` when none has been recorded. The server writes it after `verifyMcpAccessToken` admits a token with an `azp` client: off the request path, at most once per consent per hour, from the verified token and the server clock alone. A store failure never fails the MCP call and is logged once at `error`. It lands in the new `sys_oauth_consent.last_used_at` column, so a deployment picks it up at its next schema sync. Until then the reads answer `500` and the stamp logs its one error.

‎packages/platform-objects/src/apps/translations/en.objects.generated.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,10 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
18731873
},
18741874
updated_at: {
18751875
label: "Updated At"
1876+
},
1877+
last_used_at: {
1878+
label: "Last Used At",
1879+
help: "Start of the most recent hour in which the client made a verified MCP call under this consent; empty when none has been recorded"
18761880
}
18771881
}
18781882
},

‎packages/platform-objects/src/apps/translations/es-ES.objects.generated.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,10 @@ export const esESObjects: NonNullable<TranslationData['objects']> = {
18731873
},
18741874
updated_at: {
18751875
label: "Actualizado el"
1876+
},
1877+
last_used_at: {
1878+
label: "Último uso",
1879+
help: "Inicio de la hora más reciente en la que el cliente hizo una llamada MCP verificada con este consentimiento; vacío si no se ha registrado ninguna"
18761880
}
18771881
}
18781882
},

‎packages/platform-objects/src/apps/translations/ja-JP.objects.generated.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,10 @@ export const jaJPObjects: NonNullable<TranslationData['objects']> = {
18731873
},
18741874
updated_at: {
18751875
label: "更新日時"
1876+
},
1877+
last_used_at: {
1878+
label: "最終使用日時",
1879+
help: "この同意のもとでクライアントが検証済みの MCP 呼び出しを最後に行った時間帯の開始時刻。記録がない場合は空です"
18761880
}
18771881
}
18781882
},

‎packages/platform-objects/src/apps/translations/zh-CN.objects.generated.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,10 @@ export const zhCNObjects: NonNullable<TranslationData['objects']> = {
18731873
},
18741874
updated_at: {
18751875
label: "更新时间"
1876+
},
1877+
last_used_at: {
1878+
label: "最近使用时间",
1879+
help: "客户端在此同意下最近一次经验证的 MCP 调用所在小时的开始时间;尚无记录时为空"
18761880
}
18771881
}
18781882
},

‎packages/plugins/plugin-auth/src/auth-manager.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4457,21 +4457,24 @@ export class AuthManager {
44574457
* write per consent per hour, from the verified principal and the server's
44584458
* clock alone; the first failure in this process is reported at `error`
44594459
* (`error` when the host logger carries it, else `warn`, called through the
4460-
* property — see {@link audienceLogError}).
4460+
* property — see {@link audienceLogError}; `console.error` when the manager
4461+
* was given no logger, so the report is never silent).
44614462
*/
44624463
private scheduleMcpClientLastUse(principal: { userId: string; clientId?: string; organizationId?: string }): void {
44634464
if (!principal.clientId) return;
44644465
const stamper = (this.mcpClientLastUse ??= new McpClientLastUseStamper(
44654466
mcpClientLastUseStoreFor(() => this.getDataEngine()),
44664467
{
4467-
onFirstFailure: (error) =>
4468-
this.audienceLogError(
4468+
onFirstFailure: (error) => {
4469+
const message =
44694470
'[AuthManager] The last-use time of authorized AI assistants could not be recorded: '
4470-
+ 'the authorized-clients reads keep answering the last stamp that landed as if it were current. '
4471-
+ 'Check that schema sync has added sys_oauth_consent.last_used_at and that the data engine is reachable; '
4472-
+ 'each consent is retried once an hour, and only this first failure is reported.',
4473-
{ error: error instanceof Error ? error.message : String(error) },
4474-
),
4471+
+ 'the authorized-clients reads keep answering the last stamp that landed as if it were current. '
4472+
+ 'Check that schema sync has added sys_oauth_consent.last_used_at and that the data engine is reachable; '
4473+
+ 'each consent is retried once an hour, and only this first failure is reported.';
4474+
const meta = { error: error instanceof Error ? error.message : String(error) };
4475+
if (this.config.logger) this.audienceLogError(message, meta);
4476+
else console.error(message, meta);
4477+
},
44754478
},
44764479
));
44774480
runAfterResponse(

0 commit comments

Comments
 (0)