Files
zpan/shared/schemas/oauth-grants.ts
T
Jasper Van 8513b18a8e feat(oauth): expose workspace authorization catalog (#551)
* feat(oauth): expose workspace authorization catalog

* fix(oauth): verify catalog tokens against canonical audience

* fix(auth): normalize Workers preview requests

* Revert "fix(auth): normalize Workers preview requests"

This reverts commit 02009f098f.

* fix(oauth): refresh configured resource scopes
2026-08-02 21:00:20 -04:00

70 lines
2.2 KiB
TypeScript

import { z } from 'zod'
import { OAUTH_ACCESS_TOKEN_SECONDS, OAUTH_REFRESH_TOKEN_SECONDS } from '../oauth'
import { oauthGrantScopeSchema } from './oauth-resource'
export const oauthGrantStatusSchema = z.enum(['active'])
export type OAuthGrantStatus = z.infer<typeof oauthGrantStatusSchema>
export const oauthGrantSchema = z.object({
id: z.string(),
clientId: z.string(),
clientName: z.string(),
userId: z.string(),
workspaces: z.array(z.object({ id: z.string(), name: z.string().nullable() })).min(1),
scopes: z.array(oauthGrantScopeSchema),
createdAt: z.string(),
lastUsedAt: z.string().nullable(),
status: oauthGrantStatusSchema,
})
export type OAuthGrant = z.infer<typeof oauthGrantSchema>
export const oauthGrantListSchema = z.object({ items: z.array(oauthGrantSchema) })
export type OAuthGrantList = z.infer<typeof oauthGrantListSchema>
export const oauthConsentContextSchema = z.object({
clientId: z.string(),
clientName: z.string(),
clientOrigin: z.string(),
workspaces: z
.array(
z.object({
id: z.string(),
name: z.string().nullable(),
}),
)
.min(1),
requestedWorkspaceIds: z.array(z.string()),
scopes: z.array(oauthGrantScopeSchema),
standardScopes: z.array(z.string()),
redirectUri: z.string(),
grantLifetime: z.object({
accessTokenSeconds: z.number().int().default(OAUTH_ACCESS_TOKEN_SECONDS),
refreshTokenSeconds: z.number().int().default(OAUTH_REFRESH_TOKEN_SECONDS),
}),
})
export type OAuthConsentContext = z.infer<typeof oauthConsentContextSchema>
export const oauthConsentContextRequestSchema = z.object({
oauthQuery: z.string().min(1),
})
export type OAuthConsentContextRequest = z.infer<typeof oauthConsentContextRequestSchema>
export const oauthConsentSubmitSchema = z.object({
accept: z.boolean(),
oauthQuery: z.string().min(1),
workspaceIds: z.array(z.string().min(1)),
})
export type OAuthConsentSubmit = z.infer<typeof oauthConsentSubmitSchema>
export const oauthConsentResultSchema = z.object({
url: z.string(),
})
export type OAuthConsentResult = z.infer<typeof oauthConsentResultSchema>
export function oauthGrantDTO(input: Omit<OAuthGrant, 'status'>): OAuthGrant {
return {
...input,
status: 'active',
}
}