@@ -2082,10 +2082,6 @@ impl AuthorizationManager {
20822082 return Self :: dedup_scopes ( accumulated) ;
20832083 }
20842084
2085- self . select_fallback_scopes ( default_scopes)
2086- }
2087-
2088- fn select_fallback_scopes ( & self , default_scopes : & [ & str ] ) -> Vec < String > {
20892085 if let Some ( metadata) = & self . metadata
20902086 && let Some ( scopes_supported) = & metadata. scopes_supported
20912087 && !scopes_supported. is_empty ( )
@@ -6035,6 +6031,37 @@ mod tests {
60356031 assert_eq ! ( query. get( "scope" ) . map( String :: as_str) , expected_scope) ;
60366032 }
60376033
6034+ #[ tokio:: test]
6035+ async fn oauth_state_uses_initial_scopes_from_supplied_challenge ( ) {
6036+ let client = RecordingOAuthHttpClient :: with_responses ( vec ! [
6037+ http_response(
6038+ 200 ,
6039+ serde_json:: json!( {
6040+ "resource" : "https://mcp.example.com/mcp" ,
6041+ "authorization_servers" : [ "https://auth.example.com" ] ,
6042+ "scopes_supported" : [ "read" , "write" ]
6043+ } ) ,
6044+ ) ,
6045+ preregistered_as_metadata_response( ) ,
6046+ ] ) ;
6047+ let mut state = super :: OAuthState :: new_with_oauth_http_client (
6048+ "https://mcp.example.com/mcp" ,
6049+ Arc :: new ( client. clone ( ) ) ,
6050+ )
6051+ . await
6052+ . unwrap ( ) ;
6053+
6054+ let request = AuthorizationRequest :: new ( "http://localhost:8080/callback" )
6055+ . with_preregistered_client ( "preregistered-client" )
6056+ . with_challenge ( r#"Bearer resource_metadata="/metadata", scope="read""# )
6057+ . with_initial_scope_selection ( ) ;
6058+ state. start_authorization ( request) . await . unwrap ( ) ;
6059+
6060+ let query = auth_url_query ( & state. get_authorization_url ( ) . await . unwrap ( ) ) ;
6061+ assert_eq ! ( query. get( "scope" ) . unwrap( ) , "read offline_access" ) ;
6062+ assert_eq ! ( client. requests( ) [ 0 ] . uri, "https://mcp.example.com/metadata" ) ;
6063+ }
6064+
60386065 #[ tokio:: test]
60396066 async fn preregistered_client_uses_explicit_scopes_and_adds_offline_access ( ) {
60406067 let client = RecordingOAuthHttpClient :: with_responses ( preregistered_discovery_responses ( ) ) ;
0 commit comments