nitrostack 1.0.22 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/cli/commands/dev.d.ts.map +1 -1
  2. package/dist/cli/commands/dev.js +3 -1
  3. package/dist/cli/commands/dev.js.map +1 -1
  4. package/dist/cli/mcp-dev-wrapper.js +2 -1
  5. package/dist/cli/mcp-dev-wrapper.js.map +1 -1
  6. package/dist/core/app-decorator.d.ts.map +1 -1
  7. package/dist/core/app-decorator.js +24 -2
  8. package/dist/core/app-decorator.js.map +1 -1
  9. package/dist/core/di/container.d.ts.map +1 -1
  10. package/dist/core/di/container.js +14 -1
  11. package/dist/core/di/container.js.map +1 -1
  12. package/dist/core/oauth-module.d.ts +15 -42
  13. package/dist/core/oauth-module.d.ts.map +1 -1
  14. package/dist/core/oauth-module.js +130 -5
  15. package/dist/core/oauth-module.js.map +1 -1
  16. package/dist/core/server.d.ts +7 -1
  17. package/dist/core/server.d.ts.map +1 -1
  18. package/dist/core/server.js +99 -23
  19. package/dist/core/server.js.map +1 -1
  20. package/dist/core/transports/discovery-http-server.d.ts +13 -0
  21. package/dist/core/transports/discovery-http-server.d.ts.map +1 -0
  22. package/dist/core/transports/discovery-http-server.js +54 -0
  23. package/dist/core/transports/discovery-http-server.js.map +1 -0
  24. package/dist/core/transports/http-server.d.ts +6 -0
  25. package/dist/core/transports/http-server.d.ts.map +1 -1
  26. package/dist/core/transports/http-server.js +8 -0
  27. package/dist/core/transports/http-server.js.map +1 -1
  28. package/dist/core/transports/streamable-http.d.ts +5 -0
  29. package/dist/core/transports/streamable-http.d.ts.map +1 -1
  30. package/dist/core/transports/streamable-http.js +7 -0
  31. package/dist/core/transports/streamable-http.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/studio/app/api/auth/fetch-metadata/route.ts +2 -2
  34. package/src/studio/app/auth/page.tsx +16 -3
  35. package/src/studio/app/logs/page.tsx +279 -0
  36. package/src/studio/next.config.js +4 -0
  37. package/templates/typescript-auth/package.json +2 -1
  38. package/templates/typescript-auth/src/index.ts +6 -25
  39. package/templates/typescript-auth-api-key/package.json +3 -1
  40. package/templates/typescript-auth-api-key/src/index.ts +6 -26
  41. package/templates/typescript-oauth/.env.example +35 -24
  42. package/templates/typescript-oauth/OAUTH_SETUP.md +306 -120
  43. package/templates/typescript-oauth/README.md +75 -31
  44. package/templates/typescript-oauth/package.json +3 -1
  45. package/templates/typescript-oauth/src/index.ts +6 -27
  46. package/templates/typescript-starter/package.json +2 -1
  47. package/templates/typescript-starter/src/index.ts +6 -25
@@ -1,21 +1,21 @@
1
1
  # Complete OAuth 2.1 Setup Guide for NitroStack
2
2
 
3
- This guide shows you **exactly** how to set up OAuth 2.1 authentication from scratch, test it in NitroStack Studio, and deploy it to production.
3
+ This guide shows you **exactly** how to set up OAuth 2.1 authentication from scratch with **zero issues**.
4
4
 
5
5
  ## 🎯 What You'll Learn
6
6
 
7
- - ✅ How to configure Auth0 (or other OAuth providers)
7
+ - ✅ How to configure Auth0 correctly (avoiding common pitfalls)
8
8
  - ✅ How to set up your MCP server environment
9
9
  - ✅ How to test the complete OAuth flow in Studio
10
10
  - ✅ How to troubleshoot common issues
11
11
 
12
12
  ---
13
13
 
14
- ## 🚀 Quick Start with Auth0 (5 Minutes)
14
+ ## 🚀 Quick Start with Auth0 (10 Minutes)
15
15
 
16
16
  ### Why Auth0?
17
17
  - ✅ **Free tier** (7,000 active users, no credit card)
18
- - ✅ **Fastest setup** (5 minutes)
18
+ - ✅ **Fastest setup** (10 minutes)
19
19
  - ✅ **Best for testing** and learning
20
20
  - ✅ **Production-ready** when you need it
21
21
 
@@ -29,107 +29,175 @@ This guide shows you **exactly** how to set up OAuth 2.1 authentication from scr
29
29
 
30
30
  ---
31
31
 
32
- ## Step 2: Create Auth0 Application
32
+ ## Step 2: Create Auth0 API (Protected Resource)
33
33
 
34
- This represents NitroStack Studio as an OAuth client.
34
+ **⚠️ DO THIS FIRST!** The API represents your MCP server as a protected resource.
35
35
 
36
- 1. Open **Auth0 Dashboard** → **Applications** **Applications**
37
- 2. Click **"Create Application"**
36
+ 1. Go to **Applications** → **APIs** in Auth0 Dashboard
37
+ 2. Click **"Create API"**
38
38
  3. **Settings:**
39
39
  ```
40
- Name: NitroStack Studio
41
- Application Type: Regular Web Application
40
+ Name: MCP Server API
41
+ Identifier: https://mcplocal
42
+ Signing Algorithm: RS256
42
43
  ```
44
+
45
+ **⚠️ CRITICAL NOTES:**
46
+ - The **Identifier** can be any unique URI (doesn't need to be a real URL)
47
+ - For development, use `https://mcplocal` (simple and clear)
48
+ - For production, use your actual domain like `https://api.yourapp.com`
49
+ - This **MUST** match your `RESOURCE_URI` in `.env` **EXACTLY**
50
+ - **JWT Profile**: Select **RFC 9068** (OAuth 2.0 Access Token JWT Profile)
51
+ - **RBAC**: You can leave this **disabled** for basic OAuth (only needed for role-based permissions)
52
+
43
53
  4. Click **"Create"**
44
54
 
45
- 5. Go to **Settings** tab and configure:
55
+ 5. Go to **Permissions** tab
56
+ 6. Add these scopes:
57
+ ```
58
+ Scope Description
59
+ ----- -----------
60
+ read Read access to resources
61
+ write Write/modify resources
62
+ admin Administrative operations
46
63
  ```
47
- Allowed Callback URLs:
48
- http://localhost:3000/auth/callback
49
64
 
50
- Allowed Logout URLs:
51
- http://localhost:3000
65
+ 7. Click **"Add"** for each scope
66
+ 8. **Save Changes**
67
+
68
+ ---
69
+
70
+ ## Step 3: Create Auth0 Application (OAuth Client)
52
71
 
53
- Allowed Web Origins:
54
- http://localhost:3000
72
+ **⚠️ Application Type Matters!** This is where many users get stuck.
55
73
 
56
- Grant Types:
57
- Authorization Code
58
- Refresh Token
74
+ 1. Go to **Applications** → **Applications**
75
+ 2. Click **"Create Application"**
76
+ 3. **Settings:**
77
+ ```
78
+ Name: MCP Server OAuth
79
+ Application Type: Regular Web Application ← CRITICAL!
59
80
  ```
81
+
82
+ **⚠️ WHY "Regular Web Application"?**
83
+ - ❌ **NOT** "Single Page Application" (SPA) - Won't show in API authorization
84
+ - ❌ **NOT** "Machine to Machine" - Different auth flow, not compatible with OpenAI Studio
85
+ - ✅ **YES** "Regular Web Application" - Supports confidential clients with client secret
60
86
 
61
- 6. **Save Changes**
87
+ 4. Click **"Create"**
62
88
 
63
- 7. **Copy these values** (you'll need them later):
64
- - **Domain** (e.g., `dev-abc123.us.auth0.com`)
65
- - **Client ID** (e.g., `aBc123XyZ...`)
66
- - **Client Secret** (click "Reveal Auth0 Management API" to see it)
89
+ 5. Go to **Settings** tab and configure:
67
90
 
68
- ---
91
+ **Allowed Callback URLs** (supports both dev and prod):
92
+ ```
93
+ http://localhost:3005/auth/callback,http://localhost:3000/auth/callback
94
+ ```
95
+
96
+ **Why both ports?**
97
+ - `3005`: Dev mode (DiscoveryHttpServer handles OAuth callbacks)
98
+ - `3000`: Prod mode (HttpServerTransport handles OAuth callbacks)
69
99
 
70
- ## Step 3: Create Auth0 API
100
+ **Allowed Logout URLs**:
101
+ ```
102
+ http://localhost:3005,http://localhost:3000
103
+ ```
71
104
 
72
- This represents your MCP server as a protected resource.
105
+ **Allowed Web Origins**:
106
+ ```
107
+ http://localhost:3005,http://localhost:3000
108
+ ```
73
109
 
74
- 1. Go to **Applications** **APIs**
75
- 2. Click **"Create API"**
76
- 3. **Settings:**
110
+ 6. Scroll down to **Advanced Settings**
111
+ 7. Go to **Grant Types** tab:
77
112
  ```
78
- Name: NitroStack MCP Server
79
- Identifier: http://localhost:3002
80
- Signing Algorithm: RS256
113
+ Authorization Code
114
+ Refresh Token
115
+ Implicit (disable - deprecated in OAuth 2.1)
116
+ ❌ Client Credentials (not needed for this use case)
81
117
  ```
82
- **Important:** The Identifier MUST match your server's `RESOURCE_URI`
83
118
 
84
- 4. Click **"Create"**
119
+ 8. Go to **OAuth** tab:
120
+ ```
121
+ ✅ OIDC Conformant: ON (enabled)
122
+ JsonWebToken Signature Algorithm: RS256
123
+ ```
85
124
 
86
- 5. Go to **Permissions** tab
87
- 6. Add these scopes:
125
+ 9. Go to **ID Token** tab:
88
126
  ```
89
- Scope Description
90
- ----- -----------
91
- read Read access to resources
92
- write Write/modify resources
93
- admin Administrative operations
127
+ ❌ ID Token Encryption: NONE/Disabled
94
128
  ```
129
+
130
+ **⚠️ CRITICAL:** If encryption is enabled, you'll receive JWE (encrypted) tokens instead of JWT tokens, which will fail validation!
95
131
 
96
- 7. Click **"Add"** for each scope
132
+ 10. **Save Changes**
133
+
134
+ 11. **Copy these values** (you'll need them later):
135
+ - **Domain** (e.g., `dev-abc123.us.auth0.com`)
136
+ - **Client ID** (e.g., `aBc123XyZ...`)
137
+ - **Client Secret** (click "Show" to reveal it)
138
+
139
+ ---
140
+
141
+ ## Step 4: Link Application to API
142
+
143
+ **⚠️ REQUIRED STEP!** Many users miss this.
144
+
145
+ 1. Go back to **Applications** → **APIs**
146
+ 2. Click on your **"MCP Server API"** (created in Step 2)
147
+ 3. Click the **"Machine to Machine Applications"** tab
148
+
149
+ **Note:** Despite the confusing name, this tab shows which applications can access your API
150
+
151
+ 4. Find your **"MCP Server OAuth"** application in the list
152
+ 5. **Toggle the switch to "Authorized"** (should turn green)
153
+ 6. Click the **dropdown arrow** to expand permissions
154
+ 7. **Select all scopes** you want to grant (`read`, `write`, `admin`)
155
+ 8. Click **"Update"**
156
+
157
+ **✅ Verification:** Your application should now show as "Authorized" with selected scopes
97
158
 
98
159
  ---
99
160
 
100
- ## Step 4: Configure Your MCP Server
161
+ ## Step 5: Configure Your MCP Server
162
+
163
+ ### Copy and Edit `.env` File
101
164
 
102
- ### Edit `.env` File
165
+ ```bash
166
+ cp .env.example .env
167
+ ```
103
168
 
104
- Replace the values with your Auth0 settings from Steps 2 & 3:
169
+ Edit `.env` with your Auth0 settings:
105
170
 
106
171
  ```bash
107
172
  # =============================================================================
108
173
  # REQUIRED: Server Configuration
109
174
  # =============================================================================
110
175
 
111
- # Your MCP server's public URL (matches API Identifier from Step 3)
112
- RESOURCE_URI=http://localhost:3002
176
+ # ⚠️ MUST match Auth0 API Identifier from Step 2 EXACTLY
177
+ RESOURCE_URI=https://mcplocal
113
178
 
114
- # Your Auth0 domain (from Step 2)
179
+ # Your Auth0 domain from Step 3 (with https://)
115
180
  AUTH_SERVER_URL=https://dev-abc123.us.auth0.com
116
181
 
117
182
  # =============================================================================
118
183
  # OPTIONAL: Token Configuration
119
184
  # =============================================================================
120
185
 
121
- # Expected token audience (must match API Identifier)
122
- TOKEN_AUDIENCE=http://localhost:3002
186
+ # Must match RESOURCE_URI
187
+ TOKEN_AUDIENCE=https://mcplocal
123
188
 
124
- # Expected token issuer (Auth0 domain with trailing slash)
189
+ # Auth0 domain with trailing slash!
125
190
  TOKEN_ISSUER=https://dev-abc123.us.auth0.com/
126
191
  ```
127
192
 
128
- **⚠️ Important:** Replace `dev-abc123` with YOUR actual Auth0 domain!
193
+ **⚠️ Important:**
194
+ - Replace `dev-abc123` with YOUR actual Auth0 domain
195
+ - `RESOURCE_URI` must match Auth0 API Identifier **EXACTLY** (case-sensitive!)
196
+ - `TOKEN_ISSUER` must have trailing slash `/`
129
197
 
130
198
  ---
131
199
 
132
- ## Step 5: Start Your MCP Server
200
+ ## Step 6: Start Your MCP Server
133
201
 
134
202
  ```bash
135
203
  npm install
@@ -138,50 +206,59 @@ npm run dev
138
206
 
139
207
  **Expected Output:**
140
208
  ```
141
- 🌐 HTTP MCP Server listening on http://0.0.0.0:3002/mcp
142
- 🔐 OAuth 2.1 enabled
143
- Resource URI: http://localhost:3002
144
- Auth Servers: https://dev-abc123.us.auth0.com
145
- Metadata: http://0.0.0.0:3002/.well-known/oauth-protected-resource
209
+ 🚀 OAuth discovery server running at http://localhost:3005
210
+ NITRO_LOG::{"level":"info","message":"OAuthModule: Running in STDIO mode, starting DiscoveryHttpServer on port 3005"}
211
+ NITRO_LOG::{"level":"info","message":"🔐 OAuth 2.1 enabled"}
212
+ NITRO_LOG::{"level":"info","message":" Resource URI: https://mcplocal"}
213
+ NITRO_LOG::{"level":"info","message":" Auth Servers: https://dev-abc123.us.auth0.com"}
146
214
  🚀 Server started successfully (DUAL: STDIO + HTTP)
147
215
  📡 MCP Protocol: STDIO (for Studio/Claude)
148
- 🌐 OAuth Metadata: HTTP (port 3002)
216
+ 🌐 OAuth Metadata: HTTP (port 3005)
149
217
  ```
150
218
 
151
219
  **✅ Success!** Your server is running in DUAL mode:
152
220
  - **STDIO**: For MCP protocol communication (tools, chat)
153
- - **HTTP**: For OAuth metadata and discovery
221
+ - **HTTP (3005)**: For OAuth metadata and discovery in dev mode
154
222
 
155
223
  ---
156
224
 
157
- ## Step 6: Test OAuth Flow in NitroStack Studio
225
+ ## Step 7: Test OAuth Flow in NitroStack Studio
158
226
 
159
227
  ### Open Studio
160
228
 
161
229
  Navigate to **http://localhost:3000** in your browser
162
230
 
163
- ### 6.1 Discover OAuth Server
231
+ ### 7.1 Discover OAuth Server
164
232
 
165
233
  1. Go to **Auth** → **OAuth 2.1** tab
166
- 2. In the **"Discover Server Auth"** section:
234
+ 2. In the **"1. Discover Server Auth"** section:
167
235
  ```
168
- Server URL: http://localhost:3002
236
+ Server URL: http://localhost:3005
169
237
  ```
238
+ **Note:** Port 3005 in dev mode (discovery server)
239
+
170
240
  3. Click **"Discover Auth Config"**
171
241
 
172
242
  **Expected Result:**
173
243
  ```
174
- ✅ Discovery Successful
244
+ ✅ Discovery successful!
175
245
 
176
- Resource: http://localhost:3002
246
+ Resource: https://mcplocal
177
247
  Authorization Servers: https://dev-abc123.us.auth0.com
178
248
  Scopes: read, write, admin
179
249
  ```
180
250
 
181
- ### 6.2 Enter Client Credentials
251
+ **✅ In Console, you should see:**
252
+ ```
253
+ 🎯 Setting audience parameter: https://mcplocal
254
+ ```
255
+
256
+ **⚠️ This is CRITICAL!** The audience parameter tells Auth0 to issue a proper JWT access token for your API.
257
+
258
+ ### 7.2 Enter Client Credentials
182
259
 
183
260
  1. Scroll to **"2a. Use Existing Client"** section
184
- 2. Enter your credentials from Step 2:
261
+ 2. Enter your credentials from Step 3:
185
262
  ```
186
263
  Client ID: [Your Auth0 Client ID]
187
264
  Client Secret: [Your Auth0 Client Secret]
@@ -193,14 +270,14 @@ Scopes: read, write, admin
193
270
  ✅ Client credentials saved!
194
271
  ```
195
272
 
196
- ### 6.3 Start OAuth Flow
273
+ ### 7.3 Start OAuth Flow
197
274
 
198
275
  1. Scroll to **"3. Start OAuth Flow"** section
199
276
  2. Click **"Start Authorization Flow"**
200
277
 
201
278
  **What Happens:**
202
279
  1. ✅ You're redirected to Auth0 login page
203
- 2. ✅ Login with your Auth0 account
280
+ 2. ✅ Login with your Auth0 account (or test user)
204
281
  3. ✅ You're asked to authorize the application
205
282
  4. ✅ After authorization, you're redirected back to Studio
206
283
  5. ✅ Studio exchanges the code for a JWT token
@@ -211,12 +288,31 @@ Scopes: read, write, admin
211
288
  ✅ Authorization successful! Redirecting...
212
289
  ```
213
290
 
214
- ### 6.4 Test Protected Tools
291
+ ### 7.4 Verify Token Type (Debug Check)
292
+
293
+ **In your MCP server logs, you should see:**
294
+ ```
295
+ [DEBUG] Token header: {"alg":"RS256","typ":"at+jwt","kid":"..."}
296
+ [DEBUG] Decoded payload: SUCCESS
297
+ [DEBUG] Payload audience: https://mcplocal
298
+ [DEBUG] Expected audience: https://mcplocal
299
+ ```
300
+
301
+ **✅ Perfect!** You're getting **RS256 JWT tokens** (not encrypted JWE tokens)
302
+
303
+ **❌ If you see this instead:**
304
+ ```
305
+ [DEBUG] Token header: {"alg":"dir","enc":"A256GCM",...}
306
+ [ERROR] Received JWE (encrypted) token instead of JWT!
307
+ ```
308
+
309
+ **Fix:** Go back to Step 3 and disable ID Token Encryption in Application settings
310
+
311
+ ### 7.5 Test Protected Tools
215
312
 
216
313
  1. Go to **Tools** tab
217
- 2. You should see all your MCP tools loaded
218
- 3. Try a protected tool (e.g., `get_user_profile`, `list_resources`)
219
- 4. Click **"Execute"**
314
+ 2. Try a protected tool (e.g., `get_user_profile`, `list_resources`)
315
+ 3. Click **"Execute"**
220
316
 
221
317
  **Expected Result:**
222
318
  ```json
@@ -224,7 +320,8 @@ Scopes: read, write, admin
224
320
  "success": true,
225
321
  "user": {
226
322
  "sub": "auth0|xxx",
227
- "scopes": ["read", "write", "admin"]
323
+ "scopes": ["read", "write", "admin"],
324
+ "clientId": "..."
228
325
  }
229
326
  }
230
327
  ```
@@ -237,9 +334,10 @@ Scopes: read, write, admin
237
334
 
238
335
  ### Dual Transport Architecture
239
336
 
240
- NitroStack runs **two transports simultaneously**:
337
+ NitroStack automatically runs **two transports simultaneously** when OAuth is enabled:
241
338
 
242
339
  ```
340
+ Development Mode:
243
341
  ┌─────────────────────────────────────┐
244
342
  │ Your OAuth 2.1 MCP Server │
245
343
  ├─────────────────────────────────────┤
@@ -249,87 +347,159 @@ NitroStack runs **two transports simultaneously**:
249
347
  │ ├─ Connected to Studio/Claude │
250
348
  │ └─ stdin/stdout communication │
251
349
  │ │
252
- │ 🌐 HTTP Server (Port 3002)
350
+ │ 🌐 DiscoveryHttpServer (Port 3005)
253
351
  │ ├─ OAuth Metadata Endpoints │
254
352
  │ ├─ /.well-known/oauth-protected- │
255
353
  │ │ resource │
354
+ │ ├─ /auth/callback │
256
355
  │ └─ Discovery & Token Validation │
257
356
  │ │
258
357
  └─────────────────────────────────────┘
358
+
359
+ Production Mode:
360
+ ┌─────────────────────────────────────┐
361
+ │ Your OAuth 2.1 MCP Server │
362
+ ├─────────────────────────────────────┤
363
+ │ │
364
+ │ 🌐 HttpServerTransport (Port 3000) │
365
+ │ ├─ MCP Protocol (SSE) │
366
+ │ ├─ OAuth Metadata Endpoints │
367
+ │ ├─ /.well-known/oauth-protected- │
368
+ │ │ resource │
369
+ │ ├─ /auth/callback │
370
+ │ └─ All-in-one HTTP server │
371
+ │ │
372
+ └─────────────────────────────────────┘
259
373
  ```
260
374
 
261
375
  ### OAuth Flow Sequence
262
376
 
263
377
  ```
264
- 1. Studio → Discover → Your MCP Server (HTTP)
378
+ 1. Studio → Discover → Your MCP Server (HTTP :3005 in dev)
265
379
 
266
380
  Returns OAuth metadata
381
+ (includes resource URI for audience)
267
382
 
268
383
  2. Studio → Authorize → Auth0 Login Page
269
-
384
+ (with audience param)
270
385
  User logs in
271
386
 
272
387
  3. Auth0 → Redirect → Studio Callback (/auth/callback)
273
388
 
274
389
  4. Studio → Exchange → Auth0 Token Endpoint
275
-
276
- Receives JWT token
390
+ (code for token)
391
+ Receives RS256 JWT access token
392
+ (NOT encrypted JWE token!)
277
393
 
278
394
  5. Studio → Execute Tool → Your MCP Server (STDIO)
279
395
  (with JWT) ↓
280
396
  Tool validates token & executes
281
397
  ```
282
398
 
399
+ **Key Point:** Studio now automatically includes the `audience` parameter when starting the OAuth flow, which ensures Auth0 issues proper JWT tokens.
400
+
283
401
  ---
284
402
 
285
403
  ## 🚨 Troubleshooting
286
404
 
287
- ### "Discovery failed: Cannot read properties of undefined"
405
+ ### Issue: "Received JWE (encrypted) token instead of JWT!"
288
406
 
289
- **Cause:** Server URL is incorrect or server isn't running
407
+ **Symptoms:**
408
+ ```
409
+ [DEBUG] Token header: {"alg":"dir","enc":"A256GCM",...}
410
+ [ERROR] Received JWE (encrypted) token instead of JWT!
411
+ ```
412
+
413
+ **Root Cause:** One of these:
414
+ 1. ID Token Encryption is enabled in Application settings
415
+ 2. Application type is wrong (SPA instead of Regular Web App)
416
+ 3. Audience parameter not being sent (fixed in latest Studio version)
290
417
 
291
418
  **Fix:**
292
- 1. Verify server is running: `lsof -i :3002`
293
- 2. Check URL is exactly: `http://localhost:3002`
294
- 3. Test metadata endpoint: `curl http://localhost:3002/.well-known/oauth-protected-resource`
419
+ 1. Go to Applications Your Application → Settings → Advanced Settings
420
+ 2. Click **"ID Token"** tab
421
+ 3. Ensure **"ID Token Encryption"** is **Disabled** or **None**
422
+ 4. Click **"OAuth"** tab
423
+ 5. Ensure **"OIDC Conformant"** is **ON**
424
+ 6. **Save Changes**
425
+ 7. Clear Studio's saved token and re-authorize
295
426
 
296
- ### "Token audience mismatch"
427
+ ### Issue: "Application doesn't show in API's Machine to Machine tab"
297
428
 
298
- **Cause:** `RESOURCE_URI` doesn't match Auth0 API Identifier
429
+ **Root Cause:** Application type is "Single Page Application" instead of "Regular Web Application"
299
430
 
300
431
  **Fix:**
301
- 1. In Auth0: Applications → APIs → Your API → Identifier
302
- 2. In `.env`: `RESOURCE_URI` must match exactly
303
- 3. In `.env`: `TOKEN_AUDIENCE` must match exactly
432
+ 1. Delete the current application
433
+ 2. Create a new one with type **"Regular Web Application"**
434
+ 3. Follow Step 3 again
435
+
436
+ ### Issue: "Token audience mismatch"
304
437
 
305
- ### "Invalid token issuer"
438
+ **Symptoms:**
439
+ ```
440
+ OAuth token validation failed: Token audience mismatch.
441
+ Expected: https://mcplocal, Got: https://dev-abc123.us.auth0.com/api/v2/
442
+ ```
306
443
 
307
- **Cause:** `TOKEN_ISSUER` doesn't match token's `iss` claim
444
+ **Root Cause:** `RESOURCE_URI` in `.env` doesn't match Auth0 API Identifier
445
+
446
+ **Fix:**
447
+ 1. In Auth0: Applications → APIs → Your API → Settings → **Identifier**
448
+ 2. Copy the exact identifier (e.g., `https://mcplocal`)
449
+ 3. In `.env`: Set `RESOURCE_URI` to match **EXACTLY** (case-sensitive)
450
+ 4. In `.env`: Set `TOKEN_AUDIENCE` to match **EXACTLY**
451
+ 5. Restart your MCP server
452
+
453
+ ### Issue: "Discovery failed" or "Cannot read properties of undefined"
454
+
455
+ **Root Cause:** Server URL is incorrect or server isn't running
456
+
457
+ **Fix:**
458
+ 1. Verify server is running: Check for "🚀 OAuth discovery server running" in logs
459
+ 2. Check URL is exactly: `http://localhost:3005` (dev mode)
460
+ 3. Test metadata endpoint:
461
+ ```bash
462
+ curl http://localhost:3005/.well-known/oauth-protected-resource
463
+ ```
464
+ Should return:
465
+ ```json
466
+ {
467
+ "resource": "https://mcplocal",
468
+ "authorization_servers": ["https://dev-abc123.us.auth0.com"],
469
+ "scopes_supported": ["read", "write", "admin"]
470
+ }
471
+ ```
472
+
473
+ ### Issue: "Invalid token issuer"
474
+
475
+ **Root Cause:** `TOKEN_ISSUER` doesn't match token's `iss` claim
308
476
 
309
477
  **Fix:**
310
478
  1. Check Auth0 domain in dashboard
311
479
  2. Add `https://` prefix
312
480
  3. Add trailing `/`
313
- 4. Example: `https://dev-abc123.us.auth0.com/`
481
+ 4. Example: `https://dev-abc123.us.auth0.com/` (note the slash!)
314
482
 
315
- ### "Insufficient scope"
483
+ ### Issue: "Insufficient scope"
316
484
 
317
- **Cause:** Token doesn't have required scopes for the tool
485
+ **Root Cause:** Token doesn't have required scopes for the tool
318
486
 
319
487
  **Fix:**
320
- 1. In Auth0: Applications → APIs → Your API → Permissions
321
- 2. Add the required scopes
322
- 3. Re-authorize in Studio (logout and login again)
323
- 4. New token will have updated scopes
488
+ 1. In Auth0: Applications → APIs → Your API → Machine to Machine Applications
489
+ 2. Find your application and ensure it's **Authorized**
490
+ 3. Click the dropdown and **select all required scopes**
491
+ 4. Click **"Update"**
492
+ 5. In Studio: Clear the saved token and re-authorize
493
+ 6. New token will have updated scopes
324
494
 
325
- ### "Port 3002 already in use"
495
+ ### Issue: "Port 3005 already in use"
326
496
 
327
- **Cause:** Previous server instance still running
497
+ **Root Cause:** Previous server instance still running
328
498
 
329
499
  **Fix:**
330
500
  ```bash
331
- # Kill process on port 3002
332
- lsof -ti :3002 | xargs kill -9
501
+ # Kill process on port 3005
502
+ lsof -ti :3005 | xargs kill -9
333
503
 
334
504
  # Restart server
335
505
  npm run dev
@@ -374,33 +544,49 @@ TOKEN_ISSUER=https://login.microsoftonline.com/YOUR-TENANT-ID/v2.0
374
544
  - [OAuth 2.1 Draft](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-13)
375
545
  - [RFC 8707 - Resource Indicators](https://datatracker.ietf.org/doc/html/rfc8707)
376
546
  - [RFC 9728 - Protected Resource Metadata](https://datatracker.ietf.org/doc/html/rfc9728)
547
+ - [OpenAI Apps SDK - Auth](https://developers.openai.com/apps-sdk/build/auth)
377
548
 
378
549
  ---
379
550
 
380
- ## ✅ Checklist
551
+ ## ✅ Pre-Flight Checklist
381
552
 
382
553
  Before asking for help, verify:
383
554
 
384
- - [ ] Auth0 Application created with correct callback URLs
385
- - [ ] Auth0 API created with correct identifier
386
- - [ ] Scopes added to Auth0 API
387
- - [ ] `.env` file configured with correct values
388
- - [ ] Server starts successfully (check logs)
389
- - [ ] HTTP metadata endpoint accessible: `curl http://localhost:3002/.well-known/oauth-protected-resource`
390
- - [ ] Discovery works in Studio
555
+ - [ ] Auth0 API created with **RS256** signing algorithm
556
+ - [ ] Auth0 API **JWT Profile** set to **RFC 9068**
557
+ - [ ] Auth0 Application type is **"Regular Web Application"** (not SPA or M2M)
558
+ - [ ] Application has correct **callback URLs** (`http://localhost:3005/auth/callback`)
559
+ - [ ] Application **Grant Types** include "Authorization Code" and "Refresh Token"
560
+ - [ ] Application **ID Token Encryption** is **DISABLED**
561
+ - [ ] Application is **Authorized** to access the API (Machine to Machine Applications tab)
562
+ - [ ] Required **scopes** are granted to the application
563
+ - [ ] `.env` file has `RESOURCE_URI` matching Auth0 API Identifier **EXACTLY**
564
+ - [ ] `.env` file has `TOKEN_ISSUER` with **trailing slash** `/`
565
+ - [ ] Server starts successfully (check logs for "🚀 OAuth discovery server running")
566
+ - [ ] Discovery endpoint is accessible: `curl http://localhost:3005/.well-known/oauth-protected-resource`
567
+ - [ ] Discovery works in Studio (shows resource, auth servers, scopes)
391
568
  - [ ] Client credentials saved in Studio
392
569
  - [ ] OAuth flow completes successfully
570
+ - [ ] Server logs show **RS256 JWT tokens** (not JWE encrypted tokens)
393
571
  - [ ] JWT token stored in Studio (check Auth tab)
572
+ - [ ] Protected tools execute successfully
394
573
 
395
574
  **If all checkboxes are ✅ and it still doesn't work,** check the troubleshooting section above!
396
575
 
397
576
  ---
398
577
 
399
- **Need Help?** Open an issue on [GitHub](https://github.com/yourrepo/nitrostack/issues) with:
400
- 1. Your Auth0 configuration (hide secrets!)
401
- 2. Server logs
402
- 3. Browser console errors
403
- 4. Steps you've tried
578
+ ## 🎓 What We Learned (Common Pitfalls)
579
+
580
+ 1. **Application Type Matters:** Must be "Regular Web Application", not SPA or M2M
581
+ 2. **Audience Parameter is Critical:** Without it, Auth0 returns encrypted tokens (fixed in Studio)
582
+ 3. **API Identifier Must Match:** `RESOURCE_URI` must **exactly** match Auth0 API Identifier
583
+ 4. **Encryption Must Be Disabled:** ID Token encryption breaks JWT validation
584
+ 5. **Trailing Slash Matters:** `TOKEN_ISSUER` must have trailing `/` for Auth0
585
+ 6. **Authorization Required:** Application must be explicitly authorized to access the API
586
+ 7. **Port Awareness:** Dev mode uses 3005, prod mode uses 3000
587
+
588
+ ---
404
589
 
405
- Happy coding! 🚀
590
+ **Happy coding! 🚀**
406
591
 
592
+ If you have issues, check the troubleshooting section above. Most problems are solved by verifying the checklist!