Commit de38133
committed
Fix OAuth discovery fallback and URL ordering
This commit addresses two related OAuth discovery issues:
1. Enable fallback to March 2025 spec for legacy servers (issue #1495)
- Remove exception when PRM discovery fails completely
- Fall back to root-level OAuth discovery for backward compatibility
- When PRM unavailable, only check /.well-known/oauth-authorization-server
- Maintains compatibility with legacy servers like Linear and Atlassian
2. Fix OAuth discovery URL ordering (issue #1623)
- Only check path-based URLs when auth server URL contains a path
- Prevents incorrectly discovering root AS when tenant-specific AS exists
- Follows RFC 8414 priority: path-aware OAuth, then path-aware OIDC, then root
- Fixes issue where root URLs were tried before path-based OIDC URLs
Changes:
- Renamed build_protected_resource_discovery_urls to build_protected_resource_metadata_discovery_urls
- Renamed get_discovery_urls to build_oauth_authorization_server_metadata_discovery_urls
- New function signature accepts optional auth_server_url and required server_url
- Legacy behavior: when auth_server_url is None, only try root URL
- Path-aware behavior: when auth_server_url has path, only try path-based URLs
- Root behavior: when auth_server_url has no path, only try root URLs
Breaking changes:
- Some invalid server configurations will no longer work:
- No PRM available and OASM at a path other than root
- PRM returns auth server URL with path, but OASM only at root
These configurations violate RFC specifications and are not expected to exist.
Github-Issue: #1495
Github-Issue: #16231 parent 7d12e83 commit de38133
File tree
3 files changed
+56
-35
lines changed- src/mcp/client/auth
- tests/client
3 files changed
+56
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
463 | 463 | | |
464 | 464 | | |
465 | 465 | | |
466 | | - | |
| 466 | + | |
467 | 467 | | |
468 | 468 | | |
469 | | - | |
| 469 | + | |
470 | 470 | | |
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
476 | 476 | | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | 477 | | |
481 | | - | |
482 | | - | |
483 | 478 | | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
484 | 485 | | |
485 | 486 | | |
486 | 487 | | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | 488 | | |
492 | | - | |
493 | | - | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
130 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
131 | 144 | | |
132 | 145 | | |
133 | 146 | | |
| |||
137 | 150 | | |
138 | 151 | | |
139 | 152 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 153 | + | |
| 154 | + | |
146 | 155 | | |
147 | 156 | | |
148 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
149 | 166 | | |
150 | | - | |
151 | | - | |
| 167 | + | |
| 168 | + | |
152 | 169 | | |
153 | 170 | | |
154 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | | - | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
278 | | - | |
| 278 | + | |
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | | - | |
| 289 | + | |
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
312 | | - | |
313 | | - | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
314 | 319 | | |
315 | 320 | | |
316 | 321 | | |
317 | | - | |
318 | 322 | | |
319 | 323 | | |
320 | 324 | | |
| |||
1084 | 1088 | | |
1085 | 1089 | | |
1086 | 1090 | | |
1087 | | - | |
| 1091 | + | |
1088 | 1092 | | |
1089 | 1093 | | |
1090 | 1094 | | |
| |||
1224 | 1228 | | |
1225 | 1229 | | |
1226 | 1230 | | |
1227 | | - | |
| 1231 | + | |
1228 | 1232 | | |
1229 | 1233 | | |
1230 | 1234 | | |
| |||
0 commit comments