2020)
2121from mcp .shared .auth import OAuthClientMetadata
2222
23- # ============================================================================
24- # Fixtures
25- # ============================================================================
26-
2723
2824@pytest .fixture
2925def sample_id_token () -> str :
@@ -42,22 +38,23 @@ def sample_id_token() -> str:
4238@pytest .fixture
4339def 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-
8173def test_token_exchange_params_from_id_token ():
8274 """Test creating TokenExchangeParameters from ID token."""
8375 params = TokenExchangeParameters .from_id_token (
0 commit comments