Skip to content

Commit 1b20e17

Browse files
authored
fix: routing bug (#108)
1 parent b13c1d1 commit 1b20e17

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

packages/belgie-alchemy/src/belgie_alchemy/__tests__/integration/core/oauth/test_routes_register.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async def test_register_enabled_unauthenticated_allows_public_clients(
107107

108108

109109
@pytest.mark.asyncio
110-
async def test_register_enabled_unauthenticated_rejects_confidential_clients(
110+
async def test_register_enabled_unauthenticated_allows_omitted_auth_method(
111111
belgie_instance,
112112
oauth_settings: OAuthServer,
113113
) -> None:
@@ -127,6 +127,34 @@ async def test_register_enabled_unauthenticated_rejects_confidential_clients(
127127
},
128128
)
129129

130+
assert response.status_code == 200
131+
payload = response.json()
132+
assert payload["client_secret"] is not None
133+
assert payload["token_endpoint_auth_method"] == "client_secret_post" # noqa: S105
134+
135+
136+
@pytest.mark.asyncio
137+
async def test_register_enabled_unauthenticated_rejects_explicit_confidential_clients(
138+
belgie_instance,
139+
oauth_settings: OAuthServer,
140+
) -> None:
141+
settings_payload = oauth_settings.model_dump(mode="python")
142+
settings_payload["allow_dynamic_client_registration"] = True
143+
settings_payload["allow_unauthenticated_client_registration"] = True
144+
settings = OAuthServer(**settings_payload)
145+
belgie_instance.add_plugin(settings)
146+
app = FastAPI()
147+
app.include_router(belgie_instance.router)
148+
transport = httpx.ASGITransport(app=app)
149+
async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client:
150+
response = await client.post(
151+
"/auth/oauth/register",
152+
json={
153+
"redirect_uris": ["http://testserver/callback"],
154+
"token_endpoint_auth_method": "client_secret_post",
155+
},
156+
)
157+
130158
assert response.status_code == 401
131159
payload = response.json()
132160
assert payload["error"] == "invalid_request"

packages/belgie-oauth-server/src/belgie_oauth_server/plugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,9 @@ async def register_handler( # noqa: PLR0911
371371
if exc.status_code != status.HTTP_401_UNAUTHORIZED:
372372
raise
373373

374-
is_public_client = (metadata.token_endpoint_auth_method or "client_secret_post") == "none"
374+
# Treat omitted auth method like public registration here so MCP clients can
375+
# register anonymously; the provider still defaults it later.
376+
is_public_client = metadata.token_endpoint_auth_method in {None, "none"}
375377
if not authenticated:
376378
if not settings.allow_unauthenticated_client_registration:
377379
return _oauth_error(

0 commit comments

Comments
 (0)