35 lines · 1.6 KB · TypeScript
RawDownload
// ---------------------------------------------------------------------------// OAuth metadata endpoints — returned as web `Response`s for the envelope's// discovery routes.// --------------------------------------------------------------------------- import { Effect } from "effect"; import { AUTHKIT_DOMAIN, resourceUrlFor } from "./auth";import { CORS_ALLOW_ORIGIN } from "./responses"; const jsonWebResponse = (body: unknown, status = 200): Response =>  new Response(JSON.stringify(body), {    status,    headers: { "content-type": "application/json", ...CORS_ALLOW_ORIGIN },  }); // The `resource` reflects the URL-pinned org (`…/org_xxx/mcp`) when present, so a// client that discovered metadata via the org-scoped well-known doc gets back the// matching org-scoped resource id; the bare path yields the bare resource.export const protectedResourceMetadataResponse = (organizationId: string | null = null): Response =>  jsonWebResponse({    resource: resourceUrlFor(organizationId),    authorization_servers: [AUTHKIT_DOMAIN],    bearer_methods_supported: ["header"],    scopes_supported: [],  }); export const authorizationServerMetadataResponse: Effect.Effect<Response> = Effect.tryPromise({  try: async () => {    const res = await fetch(`${AUTHKIT_DOMAIN}/.well-known/oauth-authorization-server`);    if (!res.ok) return jsonWebResponse({ error: "upstream_error" }, 502);    return jsonWebResponse(await res.json());  },  catch: () => undefined,}).pipe(Effect.catchCause(() => Effect.succeed(jsonWebResponse({ error: "upstream_error" }, 502))));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t