Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/mcp/server/auth/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ async def handle(self, request: Request) -> Response:
status_code=400,
)

if not client_metadata.redirect_uris:
return PydanticJSONResponse(
content=RegistrationErrorResponse(
error="invalid_client_metadata",
error_description="redirect_uris is required for authorization_code grant",
),
status_code=400,
)

client_id_issued_at = int(time.time())
# RFC 7591 §3.2.1: client_secret_expires_at is REQUIRED whenever a client_secret is
# issued, with 0 (not omission) meaning it never expires; a public client gets none.
Expand Down
16 changes: 16 additions & 0 deletions tests/server/auth/test_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ async def test_registration_error_handling(client: httpx2.AsyncClient, oauth_pro
assert data["error_description"] == "The redirect URI is invalid"


@pytest.mark.anyio
async def test_registration_rejects_null_redirect_uris(client: httpx2.AsyncClient):
"""Explicit null redirect_uris must be rejected for authorization_code clients."""
response = await client.post(
"/register",
json={
"redirect_uris": None,
"client_name": "Null Redirect Client",
},
)
assert response.status_code == 400, response.content
data = response.json()
assert data["error"] == "invalid_client_metadata"
assert "redirect_uris" in data["error_description"]


@pytest.mark.anyio
async def test_authorize_error_handling(
client: httpx2.AsyncClient,
Expand Down
Loading