Commit f26bb2c
committed
fix: include RFC 6750 scope parameter in insufficient_scope challenge
RequireAuthMiddleware._send_auth_error built the WWW-Authenticate header
for both the 401 invalid_token and 403 insufficient_scope cases without
ever including the scope attribute, even though required_scopes was
already available on the middleware instance.
RFC 6750 3.1 says the insufficient_scope response "MAY include the
'scope' attribute with the scope necessary to access the protected
resource." Emitting it lets a client discover the correct scope to
request directly from the challenge instead of falling back to
protected-resource-metadata scopes_supported, which the SDK's client
already treats as a lower-priority signal in
get_client_metadata_scopes().
The 401 cases (no credentials, invalid token) are left unchanged: per
RFC 6750 3.1 scope is specific to the insufficient_scope error and
doesn't apply when the resource server hasn't yet determined what
scope would even satisfy the request.
Reported-by: velias
Github-Issue: #31031 parent 5f0b6af commit f26bb2c
2 files changed
Lines changed: 60 additions & 2 deletions
File tree
- src/mcp/server/auth/middleware
- tests/server/auth/middleware
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
117 | 123 | | |
118 | 124 | | |
119 | 125 | | |
120 | 126 | | |
121 | 127 | | |
122 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
123 | 131 | | |
124 | 132 | | |
125 | 133 | | |
| 134 | + | |
| 135 | + | |
126 | 136 | | |
127 | 137 | | |
128 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
349 | 397 | | |
350 | 398 | | |
351 | 399 | | |
| |||
0 commit comments