@@ -1409,14 +1409,16 @@ impl AuthorizationManager {
14091409 push_candidate ( "/.well-known/oauth-authorization-server" . to_string ( ) ) ;
14101410 push_candidate ( "/.well-known/openid-configuration" . to_string ( ) ) ;
14111411 } else {
1412- // Path components present: follow spec priority order
1412+ // Path components present: prefer OAuth discovery before OpenID Connect fallbacks.
14131413 // 1. OAuth 2.0 with path insertion
14141414 push_candidate ( format ! ( "/.well-known/oauth-authorization-server/{trimmed}" ) ) ;
1415- // 2. OpenID Connect with path insertion
1415+ // 2. OAuth 2.0 with path appending
1416+ push_candidate ( format ! ( "/{trimmed}/.well-known/oauth-authorization-server" ) ) ;
1417+ // 3. OpenID Connect with path insertion
14161418 push_candidate ( format ! ( "/.well-known/openid-configuration/{trimmed}" ) ) ;
1417- // 3 . OpenID Connect with path appending
1419+ // 4 . OpenID Connect with path appending
14181420 push_candidate ( format ! ( "/{trimmed}/.well-known/openid-configuration" ) ) ;
1419- // 4 . Canonical OAuth fallback (without path suffix)
1421+ // 5 . Canonical OAuth fallback (without path suffix)
14201422 push_candidate ( "/.well-known/oauth-authorization-server" . to_string ( ) ) ;
14211423 }
14221424
@@ -2684,61 +2686,73 @@ mod tests {
26842686
26852687 let base_url = Url :: parse ( "https://auth.example.com/tenant1" ) . unwrap ( ) ;
26862688 let urls = AuthorizationManager :: generate_discovery_urls ( & base_url) ;
2687- assert_eq ! ( urls. len( ) , 4 ) ;
2689+ assert_eq ! ( urls. len( ) , 5 ) ;
26882690 assert_eq ! (
26892691 urls[ 0 ] . as_str( ) ,
26902692 "https://auth.example.com/.well-known/oauth-authorization-server/tenant1"
26912693 ) ;
26922694 assert_eq ! (
26932695 urls[ 1 ] . as_str( ) ,
2694- "https://auth.example.com/.well-known/openid-configuration/tenant1 "
2696+ "https://auth.example.com/tenant1/ .well-known/oauth-authorization-server "
26952697 ) ;
26962698 assert_eq ! (
26972699 urls[ 2 ] . as_str( ) ,
2698- "https://auth.example.com/tenant1/ .well-known/openid-configuration"
2700+ "https://auth.example.com/.well-known/openid-configuration/tenant1 "
26992701 ) ;
27002702 assert_eq ! (
27012703 urls[ 3 ] . as_str( ) ,
2704+ "https://auth.example.com/tenant1/.well-known/openid-configuration"
2705+ ) ;
2706+ assert_eq ! (
2707+ urls[ 4 ] . as_str( ) ,
27022708 "https://auth.example.com/.well-known/oauth-authorization-server"
27032709 ) ;
27042710
27052711 let base_url = Url :: parse ( "https://auth.example.com/v1/mcp/" ) . unwrap ( ) ;
27062712 let urls = AuthorizationManager :: generate_discovery_urls ( & base_url) ;
2707- assert_eq ! ( urls. len( ) , 4 ) ;
2713+ assert_eq ! ( urls. len( ) , 5 ) ;
27082714 assert_eq ! (
27092715 urls[ 0 ] . as_str( ) ,
27102716 "https://auth.example.com/.well-known/oauth-authorization-server/v1/mcp"
27112717 ) ;
27122718 assert_eq ! (
27132719 urls[ 1 ] . as_str( ) ,
2714- "https://auth.example.com/.well-known/openid-configuration/v1/mcp "
2720+ "https://auth.example.com/v1/mcp/ .well-known/oauth-authorization-server "
27152721 ) ;
27162722 assert_eq ! (
27172723 urls[ 2 ] . as_str( ) ,
2718- "https://auth.example.com/v1/mcp/ .well-known/openid-configuration"
2724+ "https://auth.example.com/.well-known/openid-configuration/v1/mcp "
27192725 ) ;
27202726 assert_eq ! (
27212727 urls[ 3 ] . as_str( ) ,
2728+ "https://auth.example.com/v1/mcp/.well-known/openid-configuration"
2729+ ) ;
2730+ assert_eq ! (
2731+ urls[ 4 ] . as_str( ) ,
27222732 "https://auth.example.com/.well-known/oauth-authorization-server"
27232733 ) ;
27242734
27252735 let base_url = Url :: parse ( "https://auth.example.com/tenant1/subtenant" ) . unwrap ( ) ;
27262736 let urls = AuthorizationManager :: generate_discovery_urls ( & base_url) ;
2727- assert_eq ! ( urls. len( ) , 4 ) ;
2737+ assert_eq ! ( urls. len( ) , 5 ) ;
27282738 assert_eq ! (
27292739 urls[ 0 ] . as_str( ) ,
27302740 "https://auth.example.com/.well-known/oauth-authorization-server/tenant1/subtenant"
27312741 ) ;
27322742 assert_eq ! (
27332743 urls[ 1 ] . as_str( ) ,
2734- "https://auth.example.com/.well-known/openid-configuration/tenant1/subtenant "
2744+ "https://auth.example.com/tenant1/subtenant/ .well-known/oauth-authorization-server "
27352745 ) ;
27362746 assert_eq ! (
27372747 urls[ 2 ] . as_str( ) ,
2738- "https://auth.example.com/tenant1/subtenant/ .well-known/openid-configuration"
2748+ "https://auth.example.com/.well-known/openid-configuration/tenant1/subtenant "
27392749 ) ;
27402750 assert_eq ! (
27412751 urls[ 3 ] . as_str( ) ,
2752+ "https://auth.example.com/tenant1/subtenant/.well-known/openid-configuration"
2753+ ) ;
2754+ assert_eq ! (
2755+ urls[ 4 ] . as_str( ) ,
27422756 "https://auth.example.com/.well-known/oauth-authorization-server"
27432757 ) ;
27442758 }
0 commit comments