// /authorize 同意頁:極簡單檔 HTML,要求輸入 owner 祕密才發碼。零外部資源。 // 所有反射進 HTML 的 OAuth 參數都 escape,防 XSS(redirect_uri / state / client_id 由外部帶入)。 /** HTML attribute / text 跳脫。 */ export function esc(s: string): string { return s .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } /** 同意頁需要 round-trip 回 POST /authorize 的隱藏欄位。 */ export interface ConsentParams { client_id: string; redirect_uri: string; state: string; code_challenge: string; code_challenge_method: string; scope: string; resource: string; } function hidden(name: string, value: string): string { return ``; } /** * 同意頁 HTML。`error` 有值時(如祕密錯誤)顯示紅字,但仍保留隱藏欄位讓 owner 重試。 */ export function consentPage(p: ConsentParams, error?: string): string { const fields = [ hidden("client_id", p.client_id), hidden("redirect_uri", p.redirect_uri), hidden("state", p.state), hidden("code_challenge", p.code_challenge), hidden("code_challenge_method", p.code_challenge_method), hidden("scope", p.scope), hidden("resource", p.resource), ].join("\n "); const errBlock = error ? `
${esc(error)}
` : ""; return `應用程式 ${esc(p.client_id)} 想連上你的 Arcrun MCP,
這會讓它能讀寫你的 KBDB 全部資料。
祕密不正確不會發出授權碼。此頁不儲存你的輸入。
`; }