Skip to content

Commit 0e98ed3

Browse files
Issue #9 follow-up (#10)
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent e6e447c commit 0e98ed3

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

epicshop/epic-me/app/routes/oauth/authorize.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,17 @@ export async function action({ request, context }: Route.ActionArgs) {
6767
Object.fromEntries(url.searchParams),
6868
)
6969

70+
// Strip `resource` from the request — the MCP client sends its own URL
71+
// (e.g. http://localhost:56000/mcp) as the resource, but API calls go to
72+
// a different host (the Worker). Storing that as the token audience would
73+
// cause a permanent mismatch on every /db-api call. With no audience set,
74+
// the library skips audience validation entirely.
75+
const { resource: _ignored, ...requestWithoutResource } = requestParams as
76+
typeof requestParams & { resource?: string }
77+
7078
const { redirectTo } =
7179
await context.cloudflare.env.OAUTH_PROVIDER.completeAuthorization({
72-
request: requestParams,
80+
request: requestWithoutResource,
7381
userId: String(user.id),
7482
metadata: {
7583
label: user.email,

epicshop/epic-me/workers/app.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ async function stripResourceFromTokenRequest(request: Request): Promise<Request>
5050
const contentType = request.headers.get('content-type') ?? ''
5151
if (!contentType.includes('application/x-www-form-urlencoded')) return request
5252

53-
const body = await request.text()
53+
// Read from a clone so the original request body stays available.
54+
const body = await request.clone().text()
5455
const params = new URLSearchParams(body)
5556
if (!params.has('resource')) return request
5657

0 commit comments

Comments
 (0)