Skip to content

Commit 9e72ecf

Browse files
committed
fix: support HTTP token auth parameter names
1 parent 397896e commit 9e72ecf

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/mcp/client/auth/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _extract_bearer_auth_params(www_auth_header: str) -> str | None:
7070

7171

7272
_AUTH_PARAM_PATTERN = re.compile(
73-
r"(?:^|,\s*)(?P<name>[A-Za-z][A-Za-z0-9_-]*)\s*=\s*"
73+
r"(?:^|,\s*)(?P<name>[!#$%&'*+\-.^_`|~0-9A-Za-z]+)\s*=\s*"
7474
r'(?:"(?P<quoted>(?:\\.|[^"\\])*)"|(?P<unquoted>[^,\s]+))'
7575
)
7676

tests/client/test_auth.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ def test_generic_field_lookup_preserves_non_bearer_challenges():
227227
assert extract_scope_from_www_auth(response) is None
228228

229229

230+
def test_generic_field_lookup_accepts_http_token_parameter_names():
231+
"""HTTP auth-param names accept the full token grammar defined by RFC 9110."""
232+
response = httpx2.Response(
233+
401,
234+
headers={"WWW-Authenticate": 'Newauth x.trace="trace-id", client+id=client-id'},
235+
request=httpx2.Request("GET", "https://example.com"),
236+
)
237+
238+
assert extract_field_from_www_auth(response, "x.trace") == "trace-id"
239+
assert extract_field_from_www_auth(response, "client+id") == "client-id"
240+
241+
230242
def test_quoted_auth_params_handle_escaped_quotes_and_commas():
231243
"""RFC quoted-pairs do not terminate a quoted value or split its embedded comma."""
232244
response = httpx2.Response(

0 commit comments

Comments
 (0)