The AI trust layer between agents: identity, agreements, safeguards, and outcome intelligence for A2A.

Viewing files at commit 7ef7c69958caCommit detailsView latest

api/oauth-authorization-server.ts 40 lines · 1.3 KB · typescript
1
import { auth0Config } from './auth0.js';
2
3
export async function GET(request: Request): Promise<Response> {
4
  const { audience, issuer } = auth0Config();
5
  const response = await fetch(`${issuer}.well-known/oauth-authorization-server`);
6
  if (!response.ok)
7
    return Response.json({ error: 'authorization_server_metadata_unavailable' }, { status: 502 });
8
9
  const metadata = (await response.json()) as Record<string, unknown>;
10
  const origin = new URL(request.url).origin;
11
  const authorizationEndpoint = new URL(String(metadata.authorization_endpoint));
12
  authorizationEndpoint.searchParams.set('audience', audience);
13
  return Response.json(
14
    {
15
      ...metadata,
16
      issuer: origin,
17
      authorization_endpoint: authorizationEndpoint.href,
18
      registration_endpoint: `${origin}/oauth/register`,
19
      scopes_supported: ['mcp:access'],
20
    },
21
    {
22
      headers: {
23
        'access-control-allow-origin': '*',
24
        'cache-control': 'public, max-age=300',
25
      },
26
    },
27
  );
28
}
29
30
export function OPTIONS(): Response {
31
  return new Response(null, {
32
    status: 204,
33
    headers: {
34
      'access-control-allow-headers': 'content-type, mcp-protocol-version',
35
      'access-control-allow-methods': 'GET, OPTIONS',
36
      'access-control-allow-origin': '*',
37
      'access-control-max-age': '86400',
38
    },
39
  });
40
}