Skip to content

Commit 495ea7f

Browse files
committed
Use new simplified OAuth providers in conformance client
Update conformance auth client to use the new providers: - ClientCredentialsOAuthProvider for client_secret_basic flow - PrivateKeyJWTOAuthProvider with SignedJWTParameters for private_key_jwt flow This removes usage of the deprecated RFC7523OAuthClientProvider.
1 parent 623ffb0 commit 495ea7f

File tree

1 file changed

+23
-49
lines changed
  • examples/clients/conformance-auth-client/mcp_conformance_auth_client

1 file changed

+23
-49
lines changed

examples/clients/conformance-auth-client/mcp_conformance_auth_client/__init__.py

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
import httpx
3636
from mcp import ClientSession
3737
from mcp.client.auth import OAuthClientProvider, TokenStorage
38-
from mcp.client.auth.extensions.client_credentials import JWTParameters, RFC7523OAuthClientProvider
38+
from mcp.client.auth.extensions.client_credentials import (
39+
ClientCredentialsOAuthProvider,
40+
PrivateKeyJWTOAuthProvider,
41+
SignedJWTParameters,
42+
)
3943
from mcp.client.streamable_http import streamablehttp_client
4044
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken
4145
from pydantic import AnyUrl
@@ -198,32 +202,21 @@ async def run_client_credentials_jwt_client(server_url: str) -> None:
198202
if not private_key_pem:
199203
raise RuntimeError("MCP_CONFORMANCE_CONTEXT missing 'private_key_pem'")
200204

201-
# Create JWT parameters for private_key_jwt authentication
202-
jwt_params = JWTParameters(
205+
# Create JWT parameters for SDK-signed assertions
206+
jwt_params = SignedJWTParameters(
203207
issuer=client_id,
204208
subject=client_id,
205-
jwt_signing_algorithm=signing_algorithm,
206-
jwt_signing_key=private_key_pem,
209+
signing_algorithm=signing_algorithm,
210+
signing_key=private_key_pem,
207211
)
208212

209-
# Create OAuth authentication handler for client_credentials flow
210-
# Note: redirect_uris is required by the model but not used in client_credentials flow
211-
import warnings
212-
213-
with warnings.catch_warnings():
214-
warnings.simplefilter("ignore", DeprecationWarning)
215-
oauth_auth = RFC7523OAuthClientProvider(
216-
server_url=server_url,
217-
client_metadata=OAuthClientMetadata(
218-
client_name=client_id,
219-
redirect_uris=[AnyUrl("http://localhost:0/unused")], # Required but unused
220-
grant_types=["client_credentials"],
221-
response_types=[],
222-
token_endpoint_auth_method="private_key_jwt",
223-
),
224-
storage=InMemoryTokenStorage(),
225-
jwt_parameters=jwt_params,
226-
)
213+
# Create OAuth provider for client_credentials with private_key_jwt
214+
oauth_auth = PrivateKeyJWTOAuthProvider(
215+
server_url=server_url,
216+
storage=InMemoryTokenStorage(),
217+
client_id=client_id,
218+
assertion_provider=jwt_params.create_assertion_provider(),
219+
)
227220

228221
await _run_session(server_url, oauth_auth)
229222

@@ -251,34 +244,15 @@ async def run_client_credentials_basic_client(server_url: str) -> None:
251244
if not client_secret:
252245
raise RuntimeError("MCP_CONFORMANCE_CONTEXT missing 'client_secret'")
253246

254-
# Create storage pre-populated with client credentials
255-
storage = InMemoryTokenStorage()
256-
await storage.set_client_info(
257-
OAuthClientInformationFull(
258-
client_id=client_id,
259-
client_secret=client_secret,
260-
redirect_uris=[AnyUrl("http://localhost:0/unused")],
261-
token_endpoint_auth_method="client_secret_basic",
262-
)
247+
# Create OAuth provider for client_credentials with client_secret_basic
248+
oauth_auth = ClientCredentialsOAuthProvider(
249+
server_url=server_url,
250+
storage=InMemoryTokenStorage(),
251+
client_id=client_id,
252+
client_secret=client_secret,
253+
token_endpoint_auth_method="client_secret_basic",
263254
)
264255

265-
# Create OAuth authentication handler for client_credentials flow with basic auth
266-
import warnings
267-
268-
with warnings.catch_warnings():
269-
warnings.simplefilter("ignore", DeprecationWarning)
270-
oauth_auth = RFC7523OAuthClientProvider(
271-
server_url=server_url,
272-
client_metadata=OAuthClientMetadata(
273-
client_name=client_id,
274-
redirect_uris=[AnyUrl("http://localhost:0/unused")], # Required but unused
275-
grant_types=["client_credentials"],
276-
response_types=[],
277-
token_endpoint_auth_method="client_secret_basic",
278-
),
279-
storage=storage,
280-
)
281-
282256
await _run_session(server_url, oauth_auth)
283257

284258

0 commit comments

Comments
 (0)