Files
zpan/server/usecases/agent-oauth-grants.ts
T
agent-kanban[bot]andIris Tan 88916f4f03 feat: add agent oauth consent management UI (#541)
* feat: add agent oauth consent management UI

Agent-Profile: https://agent-kanban.dev/agents/7b0ab18fa695f04a

* test: cover agent oauth consent edge paths

Agent-Profile: https://agent-kanban.dev/agents/7b0ab18fa695f04a

* fix: route agent oauth consent through rpc

Agent-Profile: https://agent-kanban.dev/agents/7b0ab18fa695f04a

* test: cover agent oauth consent rpc on workers

Agent-Profile: https://agent-kanban.dev/agents/7b0ab18fa695f04a

* test: cover agent oauth grant-use middleware

Agent-Profile: https://agent-kanban.dev/agents/7b0ab18fa695f04a

---------

Co-authored-by: Iris Tan <iris-tan@mails.agent-kanban.dev>
2026-07-29 16:52:17 -04:00

45 lines
1.3 KiB
TypeScript

import {
type AgentGrantableScope,
type AgentOAuthGrant as AgentOAuthGrantDTO,
agentGrantableScopeSchema,
agentOAuthGrantDTO,
} from '@shared/schemas'
import type { Database } from '../platform/interface'
import type { Deps } from './deps'
import { notFound } from './ports'
export async function listAgentOAuthGrants(
deps: Pick<Deps, 'agentOAuth' | 'org'>,
db: Database,
input: { userId: string },
): Promise<{ items: AgentOAuthGrantDTO[] }> {
const items = await deps.agentOAuth.listGrants(db, input.userId)
const orgNames = await deps.org.getOrgNames(items.map((item) => item.orgId))
return {
items: items.map((item) =>
agentOAuthGrantDTO({
...item,
scopes: item.scopes.filter(isAgentGrantableScope),
workspaceName: orgNames.get(item.orgId) ?? null,
}),
),
}
}
function isAgentGrantableScope(scope: string): scope is AgentGrantableScope {
return agentGrantableScopeSchema.safeParse(scope).success
}
export async function revokeAgentOAuthGrant(
deps: Pick<Deps, 'agentOAuth'>,
db: Database,
input: { userId: string; grantId: string; now?: Date },
): Promise<void> {
const revoked = await deps.agentOAuth.revokeGrant(db, {
userId: input.userId,
grantId: input.grantId,
now: input.now ?? new Date(),
})
if (!revoked) throw notFound('Agent OAuth grant not found')
}