Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(control-ui): read OAuth install callback from control-api at runtime

Jose Gabriel Ramirez Encinas897655e63e69
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 86e53095b..092d6afee 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.737",
+ "version": "0.1.738",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.737",
+ "version": "0.1.738",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",
diff --git a/control-api/package.json b/control-api/package.json
index d584b970e..2b01bf382 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.737",
+ "version": "0.1.738",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/routes/admin/oauthProviders.ts b/control-api/src/routes/admin/oauthProviders.ts
index f7b2b6657..479258afc 100644
--- a/control-api/src/routes/admin/oauthProviders.ts
+++ b/control-api/src/routes/admin/oauthProviders.ts
@@ -1,5 +1,6 @@
import { Router } from 'express'
import { z } from 'zod'
+import { config } from '../../config.js'
import { asyncHandler } from '../../http/asyncHandler.js'
import { validateOAuthEndpointUrl } from '../../http/validateMcpServerSpec.js'
import {
@@ -13,9 +14,14 @@ import {
isKnownOAuthProvider,
} from '../../oauth/providers.js'
import { rootLogger } from '../../observability/logger.js'
+import { buildPublicCallbackUrl } from '../external/oauthCallback.js'
const log = rootLogger.child({ module: 'admin-oauth-providers' })
+// Stand-in callback id handed to the redirect-URI builder; it is URL-safe (encodes to
+// itself) and is replaced by the `{oauthClientId}` placeholder in the template.
+const TEMPLATE_OAUTH_CLIENT_ID = 'oauth-client-id'
+
const discoverBodySchema = z.object({ url: z.string().min(1) })
/**
@@ -57,6 +63,28 @@ export function createAdminOauthProvidersRouter(deps: AdminOauthProvidersDeps =
})
)
+ // GET /admin/oauth/callback
+ // The exact redirect URI a Marketplace (baked or generic) OAuth install registers,
+ // as a template over the derived callback id. control-ui reads it at runtime instead
+ // of a build-time mirror of CONTROL_API_OAUTH_CALLBACK_BASE_URL. `configured` follows
+ // the registry install gate (blank/whitespace base is unconfigured, and the install
+ // is rejected); it deliberately never falls back to the request Host, which behind
+ // the public proxy chain is an internal hostname.
+ router.get('/admin/oauth/callback', (req, res) => {
+ const base = config.oauthCallbackBaseUrl
+ if (!base || base.trim().length === 0) {
+ res.status(200).json({ configured: false })
+ return
+ }
+ // Render through the same builder the install/authorize path uses, so the URI
+ // the operator copies is byte-identical to the one sent to the provider.
+ const sample = buildPublicCallbackUrl(req, TEMPLATE_OAUTH_CLIENT_ID, base)
+ res.status(200).json({
+ configured: true,
+ redirectUriTemplate: `${sample.slice(0, -TEMPLATE_OAUTH_CLIENT_ID.length)}{oauthClientId}`,
+ })
+ })
+
// POST /admin/oauth/discover — dry-run generic AS discovery, no writes (D-A6/E-19.5).
router.post(
'/admin/oauth/discover',
diff --git a/control-api/test/app.oauthCallbackAuthBoundary.test.ts b/control-api/test/app.oauthCallbackAuthBoundary.test.ts
new file mode 100644
index 000000000..4d2ecad95
--- /dev/null
+++ b/control-api/test/app.oauthCallbackAuthBoundary.test.ts
@@ -0,0 +1,21 @@
+import { describe, expect, it } from 'vitest'
+import request from 'supertest'
+import { createApp } from '../src/app.js'
+import { MockGateway } from './mockGateway.js'
+
+/**
+ * The OAuth callback configuration read by the Marketplace install form lives behind
+ * requireAuthForControlUI like every other /admin route. routes.oauthProviders.test.ts
+ * mounts the router alone and cannot see that boundary; this suite pins it with the
+ * real middleware in place.
+ */
+describe('GET /api/v1/admin/oauth/callback auth boundary', () => {
+ it('rejects an unauthenticated read with 401', async () => {
+ const app = createApp(new MockGateway('mcp-server') as never)
+
+ const res = await request(app).get('/api/v1/admin/oauth/callback')
+
+ expect(res.status).toBe(401)
+ expect(res.body).toEqual({ error: 'Unauthorized' })
+ })
+})
diff --git a/control-api/test/routes.oauthProviders.test.ts b/control-api/test/routes.oauthProviders.test.ts
index 5bf2373b1..48efd9554 100644
--- a/control-api/test/routes.oauthProviders.test.ts
+++ b/control-api/test/routes.oauthProviders.test.ts
@@ -1,6 +1,7 @@
-import { describe, expect, it, vi } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import express from 'express'
import request from 'supertest'
+import { config } from '../src/config.js'
import type { PinnedTransport } from '../src/http/pinnedFetch.js'
import { discoverAuthorizationServerMetadata } from '../src/oauth/discovery.js'
import {
@@ -137,3 +138,44 @@ describe('POST /admin/oauth/discover (E-19.5)', () => {
.expect(400)
})
})
+
+// The Marketplace OAuth install form used to read its callback base from a build-time
+// NEXT_PUBLIC_* mirror that no image sets. control-api owns the value, so the form now
+// reads it at runtime from this admin endpoint. `configured` mirrors the install gate in
+// routes/admin/registry.ts (a blank/whitespace base is NOT configured), and the endpoint
+// never falls back to the request Host the way buildPublicCallbackUrl does for dev.
+describe('GET /admin/oauth/callback', () => {
+ let savedBaseUrl: string
+
+ beforeEach(() => {
+ savedBaseUrl = config.oauthCallbackBaseUrl
+ })
+
+ afterEach(() => {
+ config.oauthCallbackBaseUrl = savedBaseUrl
+ })
+
+ it('returns the exact redirect-URI template for the configured public base', async () => {
+ config.oauthCallbackBaseUrl = 'https://oauth.example.com/'
+ const res = await request(makeApp()).get('/admin/oauth/callback').expect(200)
+ expect(res.body).toEqual({
+ configured: true,
+ redirectUriTemplate: 'https://oauth.example.com/api/v1/oauth-callback/{oauthClientId}',
+ })
+ })
+
+ it('reports not configured (and no URI) when the base is unset', async () => {
+ config.oauthCallbackBaseUrl = ''
+ const res = await request(makeApp())
+ .get('/admin/oauth/callback')
+ .set('Host', 'internal-proxy.svc')
+ .expect(200)
+ expect(res.body).toEqual({ configured: false })
+ })
+
+ it('treats a whitespace-only base as not configured, matching the install gate', async () => {
+ config.oauthCallbackBaseUrl = ' '
+ const res = await request(makeApp()).get('/admin/oauth/callback').expect(200)
+ expect(res.body).toEqual({ configured: false })
+ })
+})
diff --git a/control-ui/components/OAuthInstallForm/index.tsx b/control-ui/components/OAuthInstallForm/index.tsx
index 62f30c008..cc591d683 100644
--- a/control-ui/components/OAuthInstallForm/index.tsx
+++ b/control-ui/components/OAuthInstallForm/index.tsx
@@ -6,7 +6,12 @@ import { useToast } from '@components/Toast'
import { IconCheck, IconCopy } from '@components/icons'
import { Button, Field, SelectInput, TextAreaInput, TextInput } from '@components/ui'
import { OAUTH_PROVIDER_DOC_URLS, oauthProviderLabel } from '@constants/oauthProviders'
-import { getOAuthCredentialManifest, installFromRegistry, listMcpSecrets } from '@lib/api'
+import {
+ getOAuthCallbackConfig,
+ getOAuthCredentialManifest,
+ installFromRegistry,
+ listMcpSecrets,
+} from '@lib/api'
import { copyTextToClipboard } from '@lib/clipboard'
import { isValidK8sName, toK8sName } from '@lib/k8sValidation'
import {
@@ -25,7 +30,6 @@ import {
buildOAuthRedirectUri,
deriveOAuthClientIdPreview,
formatScopesForInput,
- oauthCallbackBaseUrl,
parseScopesInput,
referenceSecretIssue,
scopesAreSatisfied,
@@ -137,6 +141,9 @@ export function OAuthInstallForm({
const [submitError, setSubmitError] = useState('')
const [installed, setInstalled] = useState(false)
const installInFlightRef = useRef(false)
+ const [callbackStatus, setCallbackStatus] = useState<'loading' | 'ready' | 'error'>('loading')
+ const [callbackTemplate, setCallbackTemplate] = useState('')
+ const [callbackError, setCallbackError] = useState('')
const genericMode = isGeneric ? effectiveClientMode(genericState) : 'confidential'
const genericPublic = isGeneric && genericMode === 'public'
@@ -182,12 +189,37 @@ export function OAuthInstallForm({
}
}, [provider, isGeneric, genericMode])
+ // The callback is deployment config owned by control-api, read once at runtime. A
+ // failed read is surfaced as its own error (not "not configured") and, like an
+ // unconfigured callback, blocks the install.
+ useEffect(() => {
+ let cancelled = false
+ ;(async () => {
+ try {
+ const config = await getOAuthCallbackConfig()
+ if (cancelled) return
+ setCallbackTemplate(config.configured ? (config.redirectUriTemplate ?? '') : '')
+ setCallbackStatus('ready')
+ } catch (error) {
+ if (cancelled) return
+ setCallbackError(
+ error instanceof Error
+ ? error.message
+ : 'Failed to load the OAuth callback configuration.'
+ )
+ setCallbackStatus('error')
+ }
+ })()
+ return () => {
+ cancelled = true
+ }
+ }, [])
+
const derivedId = useMemo(() => deriveOAuthClientIdPreview(serverName), [serverName])
- const callbackBase = oauthCallbackBaseUrl()
- const callbackConfigured = callbackBase.length > 0
+ const callbackConfigured = callbackStatus === 'ready' && callbackTemplate.length > 0
const redirectUri = useMemo(
- () => buildOAuthRedirectUri(callbackBase, derivedId),
- [callbackBase, derivedId]
+ () => buildOAuthRedirectUri(callbackTemplate, derivedId),
+ [callbackTemplate, derivedId]
)
const nameValid = isValidK8sName(serverName)
@@ -431,7 +463,15 @@ export function OAuthInstallForm({
label="Redirect URI"
description="Register this exact URI in the provider’s OAuth app."
>
- {!callbackConfigured ? (
+ {callbackStatus === 'loading' ? (
+ <p className="cu-field__hint" role="status">
+ Loading the OAuth callback configuration…
+ </p>
+ ) : callbackStatus === 'error' ? (
+ <div className="cu-banner cu-banner--error" role="alert">
+ Could not load the OAuth callback configuration: {callbackError}
+ </div>
+ ) : !callbackConfigured ? (
// Real config error: the deployment has no public callback base URL.
<div className="cu-banner cu-banner--warn" role="alert">
The public OAuth callback URL is not configured for this deployment
diff --git a/control-ui/components/__tests__/OAuthInstallForm.test.tsx b/control-ui/components/__tests__/OAuthInstallForm.test.tsx
index c3e56549f..805269308 100644
--- a/control-ui/components/__tests__/OAuthInstallForm.test.tsx
+++ b/control-ui/components/__tests__/OAuthInstallForm.test.tsx
@@ -46,11 +46,17 @@ const GENERIC_MANIFEST = {
vi.mock('../../lib/api', () => ({
apiSend: vi.fn().mockResolvedValue({}),
getOAuthCredentialManifest: vi.fn(),
+ getOAuthCallbackConfig: vi.fn(),
listMcpSecrets: vi.fn(),
discoverGenericOAuth: vi.fn(),
installFromRegistry: vi.fn().mockResolvedValue({ serverName: 'acme', namespace: 'mcp-server' }),
}))
+const CALLBACK_CONFIGURED = {
+ configured: true,
+ redirectUriTemplate: 'https://oauth.example.com/api/v1/oauth-callback/{oauthClientId}',
+}
+
const ENTRY = {
id: '1',
name: 'acme',
@@ -81,7 +87,9 @@ async function waitForLoaded(): Promise<void> {
}
beforeEach(() => {
- vi.stubEnv('NEXT_PUBLIC_CONTROL_API_OAUTH_CALLBACK_BASE_URL', 'https://oauth.example.com')
+ // Exact shape control-api's GET /admin/oauth/callback returns when
+ // CONTROL_API_OAUTH_CALLBACK_BASE_URL is set (routes/admin/oauthProviders.ts).
+ vi.mocked(api.getOAuthCallbackConfig).mockResolvedValue(CALLBACK_CONFIGURED)
vi.mocked(api.getOAuthCredentialManifest).mockResolvedValue(MANIFEST)
vi.mocked(api.listMcpSecrets).mockResolvedValue({ items: [] })
})
@@ -89,7 +97,6 @@ beforeEach(() => {
afterEach(() => {
cleanup()
vi.clearAllMocks()
- vi.unstubAllEnvs()
})
describe('OAuthInstallForm — scopes reach the submit (Fam A(3)/E-19.3)', () => {
@@ -198,14 +205,58 @@ describe('OAuthInstallForm — manifest load failure blocks the managed gate', (
})
})
+describe('OAuthInstallForm — callback configuration comes from control-api at runtime', () => {
+ it('renders the exact redirect URI from the control-api template, not a build-time env', async () => {
+ renderForm({ provider: 'google', grantScope: 'user', scopes: ['a.read'] })
+ await waitForLoaded()
+
+ expect(await screen.findByRole('textbox', { name: 'Redirect URI' })).toHaveValue(
+ 'https://oauth.example.com/api/v1/oauth-callback/acme'
+ )
+ expect(api.getOAuthCallbackConfig).toHaveBeenCalled()
+ expect(screen.queryByText(/is not configured/i)).toBeNull()
+ })
+
+ it('renders the redirect URI for the generic carril too', async () => {
+ vi.mocked(api.getOAuthCredentialManifest).mockResolvedValue(GENERIC_MANIFEST)
+ renderForm({ provider: 'generic', grantScope: 'user', scopes: [] })
+ await waitForLoaded()
+
+ expect(await screen.findByRole('textbox', { name: 'Redirect URI' })).toHaveValue(
+ 'https://oauth.example.com/api/v1/oauth-callback/acme'
+ )
+ })
+
+ it('surfaces a load failure distinctly and keeps install blocked', async () => {
+ vi.mocked(api.getOAuthCallbackConfig).mockRejectedValue(new Error('callback boom'))
+ renderForm({ provider: 'google', grantScope: 'user', scopes: ['a.read'] })
+ await waitForLoaded()
+
+ expect(await screen.findByText(/callback boom/)).toBeInTheDocument()
+ expect(screen.queryByRole('textbox', { name: 'Redirect URI' })).toBeNull()
+
+ fireEvent.click(screen.getByRole('button', { name: 'Continue' }))
+ fireEvent.change(screen.getByLabelText('Client ID', { exact: false }), {
+ target: { value: 'cid' },
+ })
+ fireEvent.change(screen.getByLabelText('Client Secret', { exact: false }), {
+ target: { value: 'csecret' },
+ })
+ fireEvent.click(screen.getByRole('button', { name: 'Continue' }))
+ expect(screen.getByRole('button', { name: 'Install connector' })).toBeDisabled()
+ })
+})
+
describe('OAuthInstallForm — callback base URL not configured', () => {
it('shows the not-configured notice and disables install', async () => {
- vi.stubEnv('NEXT_PUBLIC_CONTROL_API_OAUTH_CALLBACK_BASE_URL', '')
+ vi.mocked(api.getOAuthCallbackConfig).mockResolvedValue({ configured: false })
renderForm({ provider: 'google', grantScope: 'user', scopes: ['a.read'] })
await waitForLoaded()
// Step 0 shows the not-configured warning instead of a (broken) redirect URI.
- expect(screen.getByText(/public OAuth callback URL is not configured/i)).toBeInTheDocument()
+ expect(
+ await screen.findByText(/public OAuth callback URL is not configured/i)
+ ).toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: 'Continue' }))
fireEvent.change(screen.getByLabelText('Client ID', { exact: false }), {
diff --git a/control-ui/lib/__tests__/oauthInstall.test.ts b/control-ui/lib/__tests__/oauthInstall.test.ts
index bd4109f6d..0d37f481e 100644
--- a/control-ui/lib/__tests__/oauthInstall.test.ts
+++ b/control-ui/lib/__tests__/oauthInstall.test.ts
@@ -1,4 +1,4 @@
-import { afterEach, describe, expect, it, vi } from 'vitest'
+import { describe, expect, it } from 'vitest'
import type { RegistryEntry } from '../api'
import {
buildOAuthRedirectUri,
@@ -6,7 +6,6 @@ import {
extractOAuthImmutables,
formatScopesForInput,
getCatalogOAuthBlock,
- oauthCallbackBaseUrl,
parseScopesInput,
referenceSecretIssue,
scopesAreSatisfied,
@@ -23,10 +22,6 @@ function entryWithOAuth(oauth: unknown): RegistryEntry {
} as RegistryEntry
}
-afterEach(() => {
- vi.unstubAllEnvs()
-})
-
describe('deriveOAuthClientIdPreview', () => {
it('mirrors the control-api derivation (lowercase, hyphen-collapsed, trimmed)', () => {
// Matches control-api deriveOAuthClientId (routes/admin/registry.ts).
@@ -41,38 +36,27 @@ describe('deriveOAuthClientIdPreview', () => {
})
describe('buildOAuthRedirectUri', () => {
- it('joins the base and callback path with the id encoded', () => {
- expect(buildOAuthRedirectUri('https://oauth.example.com', 'acme')).toBe(
- 'https://oauth.example.com/api/v1/oauth-callback/acme'
- )
- })
+ // Template shape served by control-api GET /admin/oauth/callback.
+ const TEMPLATE = 'https://oauth.example.com/api/v1/oauth-callback/{oauthClientId}'
- it('strips a trailing slash from the base', () => {
- expect(buildOAuthRedirectUri('https://oauth.example.com/', 'acme')).toBe(
+ it('fills the control-api template with the encoded id', () => {
+ expect(buildOAuthRedirectUri(TEMPLATE, 'acme')).toBe(
'https://oauth.example.com/api/v1/oauth-callback/acme'
)
+ expect(buildOAuthRedirectUri(TEMPLATE, 'a b')).toBe(
+ 'https://oauth.example.com/api/v1/oauth-callback/a%20b'
+ )
})
- it('returns null when the base is missing or blank (no broken URI)', () => {
+ it('returns null when the template is missing, blank, or lacks the placeholder', () => {
expect(buildOAuthRedirectUri('', 'acme')).toBeNull()
expect(buildOAuthRedirectUri(' ', 'acme')).toBeNull()
expect(buildOAuthRedirectUri(undefined, 'acme')).toBeNull()
+ expect(buildOAuthRedirectUri('https://oauth.example.com', 'acme')).toBeNull()
})
it('returns null when the id is empty', () => {
- expect(buildOAuthRedirectUri('https://oauth.example.com', '')).toBeNull()
- })
-})
-
-describe('oauthCallbackBaseUrl', () => {
- it('reads the NEXT_PUBLIC env lazily and trims it', () => {
- vi.stubEnv('NEXT_PUBLIC_CONTROL_API_OAUTH_CALLBACK_BASE_URL', ' https://oauth.example.com ')
- expect(oauthCallbackBaseUrl()).toBe('https://oauth.example.com')
- })
-
- it('is empty when the env is unset', () => {
- vi.stubEnv('NEXT_PUBLIC_CONTROL_API_OAUTH_CALLBACK_BASE_URL', '')
- expect(oauthCallbackBaseUrl()).toBe('')
+ expect(buildOAuthRedirectUri(TEMPLATE, '')).toBeNull()
})
})
diff --git a/control-ui/lib/api.ts b/control-ui/lib/api.ts
index 6747337f8..85edb56c1 100644
--- a/control-ui/lib/api.ts
+++ b/control-ui/lib/api.ts
@@ -9,6 +9,7 @@ import type { ApiRequestError, ApiRequestOptions } from './api.types'
import type { GenericDiscoveryPrefill } from './oauthGeneric.types'
import type {
McpSecretSummary,
+ OAuthCallbackConfig,
OAuthCredentialManifest,
OAuthInstallSubmit,
} from './oauthInstall.types'
@@ -3742,6 +3743,15 @@ export async function getOAuthCredentialManifest(
) as Promise<OAuthCredentialManifest>
}
+/**
+ * The deployment's public OAuth callback for Marketplace OAuth installs. control-api
+ * owns CONTROL_API_OAUTH_CALLBACK_BASE_URL and returns the exact redirect-URI template
+ * (over `{oauthClientId}`), or `configured: false` when none is set.
+ */
+export async function getOAuthCallbackConfig(): Promise<OAuthCallbackConfig> {
+ return apiGet('/api/v1/admin/oauth/callback') as Promise<OAuthCallbackConfig>
+}
+
/**
* Dry-run generic AS discovery (E-19.5, D-A6). Posts the operator-typed issuer/URL and
* resolves to the prefill SUGGESTION the wizard offers on Apply. No writes. On failure
diff --git a/control-ui/lib/oauthInstall.ts b/control-ui/lib/oauthInstall.ts
index 4031267f1..01a4b03e4 100644
--- a/control-ui/lib/oauthInstall.ts
+++ b/control-ui/lib/oauthInstall.ts
@@ -11,18 +11,15 @@ import type {
import { readRemoteImmutables } from './oauthRemote'
import type { RemoteImmutableView } from './oauthRemote.types'
-// Public callback base URL for the exact redirect URI (D-B4). It is a control-api
-// server env (CONTROL_API_OAUTH_CALLBACK_BASE_URL) and is NOT reachable from the
-// browser, so control-ui reads a mirror. When it is unset the wizard refuses to
-// invent a URI from window.location (a control-ui origin behind the funnel would
-// guide the operator to register a broken redirect at the provider); it shows a
-// "not configured" state instead, and control-api independently rejects the
-// install with the same reason. Read lazily (not a module-load const) so the
-// value reflects the deployment env at call time — Next still inlines the
-// NEXT_PUBLIC_* reference at build for the browser bundle.
-export function oauthCallbackBaseUrl(): string {
- return process.env.NEXT_PUBLIC_CONTROL_API_OAUTH_CALLBACK_BASE_URL?.trim() ?? ''
-}
+// The public callback base URL for the exact redirect URI (D-B4) is a control-api
+// server env (CONTROL_API_OAUTH_CALLBACK_BASE_URL). The wizard reads it at runtime
+// from control-api (GET /admin/oauth/callback) as a template over this placeholder,
+// never from a build-time NEXT_PUBLIC_* mirror. When control-api reports it unset the
+// wizard refuses to invent a URI from window.location (a control-ui origin behind the
+// funnel would guide the operator to register a broken redirect at the provider); it
+// shows a "not configured" state instead, and control-api independently rejects the
+// install with the same reason.
+const OAUTH_CLIENT_ID_PLACEHOLDER = '{oauthClientId}'
const GRANT_SCOPES: ReadonlySet<string> = new Set<OAuthGrantScope>(['user', 'context'])
@@ -99,15 +96,19 @@ export function deriveOAuthClientIdPreview(serverName: string): string {
}
/**
- * The exact redirect URI the operator registers at the provider (D-B4):
- * `{base}/api/v1/oauth-callback/{oauth.id}`. Returns null when the base URL is
- * not configured or the id is empty — the caller shows a "not configured" notice
- * rather than a broken URI.
+ * The exact redirect URI the operator registers at the provider (D-B4), filled from
+ * control-api's `redirectUriTemplate` (GET /admin/oauth/callback), which control-api
+ * renders with the same builder its install/authorize path uses. Returns null when
+ * there is no usable template (not configured) or the id is empty — the caller shows
+ * a notice rather than a broken URI.
*/
-export function buildOAuthRedirectUri(base: string | undefined, oauthId: string): string | null {
- const trimmedBase = (base ?? '').trim().replace(/\/+$/, '')
- if (!trimmedBase || !oauthId) return null
- return `${trimmedBase}/api/v1/oauth-callback/${encodeURIComponent(oauthId)}`
+export function buildOAuthRedirectUri(
+ template: string | undefined,
+ oauthId: string
+): string | null {
+ const trimmed = (template ?? '').trim()
+ if (!trimmed.includes(OAUTH_CLIENT_ID_PLACEHOLDER) || !oauthId) return null
+ return trimmed.replace(OAUTH_CLIENT_ID_PLACEHOLDER, encodeURIComponent(oauthId))
}
/**
diff --git a/control-ui/lib/oauthInstall.types.ts b/control-ui/lib/oauthInstall.types.ts
index 01a965f42..992bc5bf2 100644
--- a/control-ui/lib/oauthInstall.types.ts
+++ b/control-ui/lib/oauthInstall.types.ts
@@ -63,6 +63,14 @@ export type OAuthCredentialManifest = {
fields: OAuthCredentialField[]
}
+// GET /admin/oauth/callback — the deployment's public OAuth callback, owned by
+// control-api (CONTROL_API_OAUTH_CALLBACK_BASE_URL). `redirectUriTemplate` carries the
+// literal `{oauthClientId}` placeholder and is present only when `configured`.
+export type OAuthCallbackConfig = {
+ configured: boolean
+ redirectUriTemplate?: string
+}
+
// GET /admin/mcp-secrets item — names + keys only, never values (E-16.1).
export type McpSecretSummary = {
name: string
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 131a17269..89df19642 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.728",
+ "version": "0.1.729",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.728",
+ "version": "0.1.729",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index 6cda74840..a23f3ab42 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.728",
+ "version": "0.1.729",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",