Skip to content

Commit 84162df

Browse files
committed
- Updated test case to include IDJAGClaims type model to verify payload.
1 parent 28bb315 commit 84162df

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

tests/client/auth/test_enterprise_managed_auth_client.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
)
2121
from mcp.shared.auth import OAuthClientMetadata
2222

23-
# ============================================================================
24-
# Fixtures
25-
# ============================================================================
26-
2723

2824
@pytest.fixture
2925
def sample_id_token() -> str:
@@ -42,22 +38,23 @@ def sample_id_token() -> str:
4238
@pytest.fixture
4339
def sample_id_jag() -> str:
4440
"""Generate a sample ID-JAG token for testing."""
45-
payload = {
46-
"jti": "unique-jwt-id-12345",
47-
"iss": "https://idp.example.com",
48-
"sub": "user123",
49-
"aud": "https://auth.mcp-server.example/",
50-
"resource": "https://mcp-server.example/",
51-
"client_id": "mcp-client-app",
52-
"exp": int(time.time()) + 300,
53-
"iat": int(time.time()),
54-
"scope": "read write",
55-
}
56-
token = jwt.encode(payload, "secret", algorithm="HS256")
41+
# Create typed claims using IDJAGClaims model
42+
claims = IDJAGClaims(
43+
typ="oauth-id-jag+jwt",
44+
jti="unique-jwt-id-12345",
45+
iss="https://idp.example.com",
46+
sub="user123",
47+
aud="https://auth.mcp-server.example/",
48+
resource="https://mcp-server.example/",
49+
client_id="mcp-client-app",
50+
exp=int(time.time()) + 300,
51+
iat=int(time.time()),
52+
scope="read write",
53+
email=None, # Optional field
54+
)
5755

58-
# Manually add typ to header
59-
header = jwt.get_unverified_header(token)
60-
header["typ"] = "oauth-id-jag+jwt"
56+
# Dump to dict for JWT encoding (exclude typ as it goes in header)
57+
payload = claims.model_dump(exclude={"typ"}, exclude_none=True)
6158

6259
return jwt.encode(payload, "secret", algorithm="HS256", headers={"typ": "oauth-id-jag+jwt"})
6360

@@ -73,11 +70,6 @@ def mock_token_storage() -> Any:
7370
return storage
7471

7572

76-
# ============================================================================
77-
# Tests for TokenExchangeParameters
78-
# ============================================================================
79-
80-
8173
def test_token_exchange_params_from_id_token():
8274
"""Test creating TokenExchangeParameters from ID token."""
8375
params = TokenExchangeParameters.from_id_token(

0 commit comments

Comments
 (0)