Add OAuth-protected MCP server with generated API client packages

This commit is contained in:
Mike Cao committed 2026-09-03 16:58:47 -07:00
1 parent 26e236c95c
commit 65bf19e067
235 files changed
+33755 -3199

No files matched your search

+16
View File
@@ -15,6 +15,7 @@ import {
} from '@/lib/constants';
import { createAuthKey, hash, secret } from '@/lib/crypto';
import { createSecureToken, parseSecureToken, parseToken } from '@/lib/jwt';
import { verifyOAuthRequest } from '@/lib/oauth/verify';
import redis from '@/lib/redis';
import { ensureArray } from '@/lib/utils';
import { getApiKeyByHash, updateApiKeyLastUsed } from '@/queries/prisma/apiKey';
@@ -62,6 +63,7 @@ export async function checkApiKeyAuth(request: Request, token: string) {
return {
token,
user,
authType: 'api-key' as const,
apiKey: { id: apiKey.id, name: apiKey.name },
};
}
@@ -73,6 +75,19 @@ export async function checkAuth(request: Request) {
return checkApiKeyAuth(request, token);
}
// OAuth access tokens are only honoured on routes that explicitly opted in (see
// src/lib/oauth/scopes.ts) and never fall through to session handling.
const oauth = await verifyOAuthRequest(token, request.method, new URL(request.url).pathname);
if (oauth.status === 'ok') {
return oauth.auth;
}
if (oauth.status !== 'not-oauth') {
log('OAuth token rejected', oauth);
return null;
}
const payload = parseSecureToken(token, secret());
const shareToken = await parseShareToken(request);
@@ -131,6 +146,7 @@ export async function checkAuth(request: Request) {
authKey,
shareToken,
user,
authType: user ? ('session' as const) : ('share' as const),
};
}