@@ -78,6 +78,7 @@ async def callback_handler() -> tuple[str, str | None]:
7878 callback_handler = callback_handler ,
7979 )
8080
81+
8182@pytest .fixture
8283def oauth_provider_without_scope (oauth_provider : OAuthClientProvider ) -> OAuthClientProvider :
8384 """Create OAuth provider without predefined scope."""
@@ -119,6 +120,22 @@ def prm_metadata_without_scopes():
119120 scopes_supported = None ,
120121 )
121122
123+
124+ @pytest .fixture
125+ def oauth_metadata_response_without_scopes ():
126+ """OAuth metadata response without scopes."""
127+ return httpx .Response (
128+ 200 ,
129+ content = (
130+ b'{"issuer": "https://auth.example.com", '
131+ b'"authorization_endpoint": "https://auth.example.com/authorize", '
132+ b'"token_endpoint": "https://auth.example.com/token", '
133+ b'"registration_endpoint": "https://auth.example.com/register"}'
134+ # No scopes_supported field
135+ ),
136+ )
137+
138+
122139class TestPKCEParameters :
123140 """Test PKCE parameter generation."""
124141
@@ -433,8 +450,10 @@ async def test_handle_metadata_response_success(self, oauth_provider: OAuthClien
433450
434451 @pytest .mark .anyio
435452 async def test_prioritize_prm_scopes_over_oauth_metadata (
436- self , oauth_provider_without_scope : OAuthClientProvider ,
437- oauth_metadata_response : httpx .Response , prm_metadata : ProtectedResourceMetadata
453+ self ,
454+ oauth_provider_without_scope : OAuthClientProvider ,
455+ oauth_metadata_response : httpx .Response ,
456+ prm_metadata : ProtectedResourceMetadata ,
438457 ):
439458 """Test that PRM scopes are prioritized over auth server metadata scopes."""
440459 provider = oauth_provider_without_scope
@@ -450,8 +469,10 @@ async def test_prioritize_prm_scopes_over_oauth_metadata(
450469
451470 @pytest .mark .anyio
452471 async def test_fallback_to_oauth_metadata_scopes_when_no_prm_scopes (
453- self , oauth_provider_without_scope : OAuthClientProvider ,
454- oauth_metadata_response : httpx .Response , prm_metadata_without_scopes : ProtectedResourceMetadata
472+ self ,
473+ oauth_provider_without_scope : OAuthClientProvider ,
474+ oauth_metadata_response : httpx .Response ,
475+ prm_metadata_without_scopes : ProtectedResourceMetadata ,
455476 ):
456477 """Test fallback to OAuth metadata scopes when PRM has no scopes."""
457478 provider = oauth_provider_without_scope
@@ -467,37 +488,29 @@ async def test_fallback_to_oauth_metadata_scopes_when_no_prm_scopes(
467488
468489 @pytest .mark .anyio
469490 async def test_no_scope_changes_when_both_missing (
470- self , oauth_provider_without_scope : OAuthClientProvider ,
471- prm_metadata_without_scopes : ProtectedResourceMetadata
491+ self ,
492+ oauth_provider_without_scope : OAuthClientProvider ,
493+ prm_metadata_without_scopes : ProtectedResourceMetadata ,
494+ oauth_metadata_response_without_scopes : httpx .Response ,
472495 ):
473496 """Test that no scope changes occur when both PRM and OAuth metadata lack scopes."""
474497 provider = oauth_provider_without_scope
475498
476499 # Set up PRM metadata without scopes
477500 provider .context .protected_resource_metadata = prm_metadata_without_scopes
478501
479- # Create OAuth metadata response without scopes
480- custom_oauth_metadata_response = httpx .Response (
481- 200 ,
482- content = (
483- b'{"issuer": "https://auth.example.com", '
484- b'"authorization_endpoint": "https://auth.example.com/authorize", '
485- b'"token_endpoint": "https://auth.example.com/token", '
486- b'"registration_endpoint": "https://auth.example.com/register"}'
487- # No scopes_supported field
488- ),
489- )
490-
491502 # Process the OAuth metadata
492- await provider ._handle_oauth_metadata_response (custom_oauth_metadata_response )
503+ await provider ._handle_oauth_metadata_response (oauth_metadata_response_without_scopes )
493504
494505 # Verify that scope remains None
495506 assert provider .context .client_metadata .scope is None
496507
497508 @pytest .mark .anyio
498509 async def test_preserve_existing_client_scope (
499- self , oauth_provider : OAuthClientProvider ,
500- oauth_metadata_response : httpx .Response , prm_metadata : ProtectedResourceMetadata
510+ self ,
511+ oauth_provider : OAuthClientProvider ,
512+ oauth_metadata_response : httpx .Response ,
513+ prm_metadata : ProtectedResourceMetadata ,
501514 ):
502515 """Test that existing client scope is preserved regardless of metadata."""
503516 provider = oauth_provider
@@ -1079,4 +1092,3 @@ async def callback_handler() -> tuple[str, str | None]:
10791092
10801093 result = provider ._extract_resource_metadata_from_www_auth (init_response )
10811094 assert result is None , f"Should return None for { description } "
1082-
0 commit comments