Skip to content

Commit 951e50f

Browse files
committed
address good feedback from @localden
1 parent 8544917 commit 951e50f

File tree

7 files changed

+17
-16
lines changed

7 files changed

+17
-16
lines changed

epicshop/epic-me/app/routes/test-auth.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function loader({ request, context }: Route.LoaderArgs) {
5252
if (users.length === 0) {
5353
return Response.json({ error: 'No users available' }, { status: 400 })
5454
}
55-
userId = String(users[0].id)
55+
userId = String(users[0]?.id)
5656
}
5757

5858
const user = await context.db.getUserById(Number(userId))

epicshop/epic-me/tsconfig.cloudflare.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"workers/**/*",
1010
"types/**/*"
1111
],
12+
"exclude": ["**/node_modules/**/*", "**/dist/**/*"],
1213
"compilerOptions": {
1314
"composite": true,
1415
"strict": true,

exercises/01.start/01.solution/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"scripts": {
66
"dev": "mcp-dev stdio",
77
"dev:mcp": "tsx src/index.ts",
8-
"test": "vitest",
8+
"test": "vitest run",
9+
"test:watch": "vitest --watch",
910
"typecheck": "tsc",
1011
"inspect": "mcp-inspector"
1112
},

exercises/02.start/01.solution/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"test": "vitest",
6+
"test": "vitest run",
7+
"test:watch": "vitest --watch",
78
"pretypecheck": "wrangler types ./types/worker-configuration.d.ts",
89
"typecheck": "tsc",
910
"build": "wrangler build",

exercises/99.finished/99.solution/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"test": "vitest",
6+
"test": "vitest run",
7+
"test:watch": "vitest --watch",
78
"pretypecheck": "wrangler types ./types/worker-configuration.d.ts",
89
"typecheck": "tsc",
910
"build": "wrangler build",

exercises/99.finished/99.solution/src/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export function initiateOAuthFlow(request: Request) {
6767
return new Response('Unauthorized', {
6868
status: 401,
6969
headers: {
70-
'WWW-Authenticate': `OAuth realm="EpicMe", authorization_url="${authUrl.toString()}"`,
70+
'WWW-Authenticate': 'OAuth realm="EpicMe"',
71+
Location: authUrl.toString(),
7172
},
7273
})
7374
}
@@ -84,7 +85,7 @@ export async function getOAuthAuthorizationServerConfig() {
8485
export async function getOAuthProtectedResourceConfig() {
8586
// This server is the protected resource server, so we return our own configuration
8687
return {
87-
resource: 'epicme-mcp',
88+
resource: `${EPIC_ME_SERVER_URL}/mcp`,
8889
scopes: ['read', 'write'],
8990
resource_owner: 'epicme',
9091
resource_server: {

exercises/99.finished/99.solution/test/index.test.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,14 @@ test('OAuth integration flow works end-to-end', async () => {
8686
wwwAuthHeader,
8787
'🚨 WWW-Authenticate header should contain OAuth realm',
8888
).toContain('OAuth realm="EpicMe"')
89-
expect(
90-
wwwAuthHeader,
91-
'🚨 WWW-Authenticate header should contain authorization_url',
92-
).toContain('authorization_url=')
9389

94-
// Extract the authorization URL from the header
95-
const authUrlMatch = wwwAuthHeader?.match(/authorization_url="([^"]+)"/)
90+
// Extract the authorization URL from the Location header
91+
const locationHeader = unauthorizedResponse.headers.get('Location')
9692
expect(
97-
authUrlMatch,
98-
'🚨 Could not extract authorization URL from WWW-Authenticate header',
93+
locationHeader,
94+
'🚨 Location header should be present with authorization URL',
9995
).toBeTruthy()
100-
const authorizationUrl = authUrlMatch![1]
96+
const authorizationUrl = locationHeader
10197
expect(
10298
authorizationUrl,
10399
'🚨 Authorization URL should not be empty',
@@ -138,7 +134,7 @@ test('OAuth integration flow works end-to-end', async () => {
138134
expect(
139135
protectedResourceConfig.resource,
140136
'🚨 Resource identifier should be present',
141-
).toBe('epicme-mcp')
137+
).toBe(`${EPIC_ME_SERVER_URL}/mcp`)
142138
expect(
143139
protectedResourceConfig.scopes,
144140
'🚨 Scopes should be present',

0 commit comments

Comments
 (0)