+server.js 829 B

123456789101112131415161718192021222324252627
  1. import { getSqlite3 } from '$lib/sqlite3/database.js';
  2. /**
  3. * OAuth 2.0 Protected Resource Metadata endpoint (RFC 9728).
  4. *
  5. * Exposed at /.well-known/oauth-protected-resource to allow MCP clients and
  6. * other OAuth-aware clients to discover the authorization server(s) that
  7. * govern access to this resource server.
  8. */
  9. export async function GET(event) {
  10. const baseUrl = event.url.origin;
  11. const db = await getSqlite3();
  12. const rows = db.prepare('SELECT name FROM scopes').all();
  13. const scopesSupported = rows.map(r => r.name);
  14. const metadata = {
  15. // REQUIRED per RFC 9728 Section 2: at least one authorization server
  16. authorization_servers: [ baseUrl ],
  17. scopes_supported: scopesSupported
  18. };
  19. return new Response(JSON.stringify(metadata), {
  20. headers: { 'Content-Type': 'application/json' }
  21. });
  22. }