|
17 | 17 | * - **The MCP door reads it on every request** ({@link mcpConsentAdmits}, |
18 | 18 | * called by `verifyMcpAccessToken`). A token whose consent is gone, or |
19 | 19 | * whose consent was created after the token was issued (revoked, then |
20 | | - * granted again), verifies as no principal. A store error refuses too. |
21 | | - * `@objectstack/spec` `IAuthService.verifyMcpAccessToken` already says |
22 | | - * this: a falsy value when the token is revoked, and callers fail CLOSED. |
| 20 | + * granted again), verifies as no principal, and so does a token whose |
| 21 | + * client is disabled (objectstack-ai/cloud#3820, card 2). A store error |
| 22 | + * refuses too. `@objectstack/spec` `IAuthService.verifyMcpAccessToken` |
| 23 | + * already says this: a falsy value when the token is revoked, and callers |
| 24 | + * fail CLOSED. |
23 | 25 | * - **`/oauth2/revoke` deletes it** ({@link answerMcpTokenRevocation}) and |
24 | 26 | * revokes the grant's refresh family: the client's refresh tokens for that |
25 | 27 | * user, except those minted under another organization |
@@ -196,38 +198,62 @@ async function grantRowsOf( |
196 | 198 | const consentsOf = (store: OAuthGrantStore, grant: McpGrantKey) => |
197 | 199 | grantRowsOf(store, 'oauthConsent', grant, isConsentFor); |
198 | 200 |
|
199 | | -/** Whether the client is a server-only `skip_consent` client: one that never has a consent row. */ |
200 | | -async function isSkipConsentClient(store: OAuthGrantStore, clientId: string): Promise<boolean> { |
201 | | - const client = (await store.findOne({ |
| 201 | +/** The client row as the adapter answers it (the provider's field names), or `null` when there is none. */ |
| 202 | +async function clientOf( |
| 203 | + store: OAuthGrantStore, |
| 204 | + clientId: string, |
| 205 | +): Promise<{ skipConsent?: unknown; disabled?: unknown } | null> { |
| 206 | + return (await store.findOne({ |
202 | 207 | model: 'oauthClient', |
203 | 208 | where: [{ field: 'clientId', value: clientId }], |
204 | | - })) as { skipConsent?: unknown } | null; |
205 | | - return client?.skipConsent === true; |
| 209 | + })) as { skipConsent?: unknown; disabled?: unknown } | null; |
| 210 | +} |
| 211 | + |
| 212 | +/** Whether the client is a server-only `skip_consent` client: one that never has a consent row. */ |
| 213 | +async function isSkipConsentClient(store: OAuthGrantStore, clientId: string): Promise<boolean> { |
| 214 | + return (await clientOf(store, clientId))?.skipConsent === true; |
206 | 215 | } |
207 | 216 |
|
208 | 217 | /** |
209 | | - * The consent read the MCP door makes on every request: does the grant a |
| 218 | + * The grant read the MCP door makes on every request: does the grant a |
210 | 219 | * verified token was minted under still stand? |
211 | 220 | * |
212 | | - * Admits when the consent for (`azp`, `sub`, organization) exists and was |
213 | | - * created no later than the token was issued (compared in whole seconds, the |
214 | | - * unit of `iat`). Refuses when it is missing, when it is newer than the token |
215 | | - * (revoked and granted again: the old token belongs to the old grant), when |
216 | | - * `iat` or the row's `createdAt` cannot be read, and when there is no store. |
217 | | - * A store error propagates, and the verifier answers it as a refusal. |
| 221 | + * First the client (objectstack-ai/cloud#3820, card 2): a token whose client |
| 222 | + * is disabled (`sys_oauth_application.disabled`, the Disable action and |
| 223 | + * `POST /auth/admin/oauth2/toggle-disabled`), or whose client row is gone, is |
| 224 | + * refused. The provider already refuses a disabled client a new token |
| 225 | + * (`invalid_client` at the token endpoint, `client_disabled` at authorize) |
| 226 | + * and answers its tokens inactive at introspection, by the same truthy test |
| 227 | + * on the same column. Only this door read none of it, so a token minted |
| 228 | + * before the disable was served until it expired, up to the provider's |
| 229 | + * 3600 s access-token life. Disabling pauses the grant; it does not end it: |
| 230 | + * the consent and the refresh family stay, so once the client is enabled |
| 231 | + * again the same token and its refresh are served again. Ending the grant is |
| 232 | + * the withdraw (`authorized-clients-withdraw.ts`) or `/oauth2/revoke`. |
| 233 | + * |
| 234 | + * Then the consent: admits when the consent for (`azp`, `sub`, |
| 235 | + * organization) exists and was created no later than the token was issued |
| 236 | + * (compared in whole seconds, the unit of `iat`). Refuses when it is missing, |
| 237 | + * when it is newer than the token (revoked and granted again: the old token |
| 238 | + * belongs to the old grant), when `iat` or the row's `createdAt` cannot be |
| 239 | + * read, and when there is no store. A server-only `skip_consent` client, |
| 240 | + * which has no consent row at all, is admitted without one (ruling A, |
| 241 | + * step 5), read off the client row already in hand. A store error |
| 242 | + * propagates, and the verifier answers it as a refusal. |
218 | 243 | * |
219 | | - * One indexed read for a client that consents. Only when that read finds no |
220 | | - * consent is the client read, so that a server-only `skip_consent` client, |
221 | | - * which has no consent row at all, is admitted (ruling A, step 5). |
| 244 | + * Two indexed reads per call: the client by its unique `client_id`, and the |
| 245 | + * consent by (`client_id`, `user_id`). |
222 | 246 | */ |
223 | 247 | export async function mcpConsentAdmits( |
224 | 248 | store: OAuthGrantStore | undefined, |
225 | 249 | grant: McpGrantKey, |
226 | 250 | issuedAt: number | undefined, |
227 | 251 | ): Promise<boolean> { |
228 | 252 | if (!store) return false; |
| 253 | + const client = await clientOf(store, grant.clientId); |
| 254 | + if (!client || client.disabled) return false; |
229 | 255 | const [consent] = await consentsOf(store, grant); |
230 | | - if (!consent) return isSkipConsentClient(store, grant.clientId); |
| 256 | + if (!consent) return client.skipConsent === true; |
231 | 257 | if (typeof issuedAt !== 'number' || !Number.isFinite(issuedAt)) return false; |
232 | 258 | const createdAtMs = |
233 | 259 | consent.createdAt instanceof Date || typeof consent.createdAt === 'string' || typeof consent.createdAt === 'number' |
|
0 commit comments