@@ -1558,11 +1558,39 @@ impl AuthorizationManager {
15581558 /// # }
15591559 /// ```
15601560 pub async fn resolve_metadata ( & self ) -> Result < AuthorizationMetadataResolution , AuthError > {
1561- self . reset_initial_scopes ( ) . await ;
1562- self . resolve_metadata_inner ( ) . await
1561+ self . resolve_metadata_from_challenge ( None ) . await
15631562 }
15641563
1565- async fn resolve_metadata_inner ( & self ) -> Result < AuthorizationMetadataResolution , AuthError > {
1564+ /// Resolve authorization server metadata starting from the
1565+ /// `WWW-Authenticate` challenge of a real request's 401 response — the
1566+ /// reactive discovery path, matching the TypeScript and Python SDKs.
1567+ ///
1568+ /// Seeds scope selection with the challenge's `scope` hint and prefers
1569+ /// the challenge's `resource_metadata` URL; falls back to ordinary metadata
1570+ /// discovery when the challenge is `None` or carries no usable metadata pointer.
1571+ pub async fn resolve_metadata_from_challenge (
1572+ & self ,
1573+ www_authenticate : Option < & str > ,
1574+ ) -> Result < AuthorizationMetadataResolution , AuthError > {
1575+ * self . initial_scopes . write ( ) . await = InitialScopeState :: default ( ) ;
1576+
1577+ if let Some ( www_authenticate) = www_authenticate {
1578+ let params = WWWAuthenticateParams :: parse ( www_authenticate, & self . base_url ) ;
1579+ self . record_initial_challenge_scope ( Some ( & params) ) . await ;
1580+ self . record_challenge_scope ( & params) . await ;
1581+
1582+ if let Some ( resource_metadata_url) = & params. resource_metadata_url
1583+ && let Some ( metadata) = self
1584+ . discover_oauth_server_from_resource_metadata_url ( resource_metadata_url)
1585+ . await ?
1586+ {
1587+ return Ok ( AuthorizationMetadataResolution {
1588+ metadata,
1589+ source : AuthorizationMetadataSource :: ProtectedResourceMetadata ,
1590+ } ) ;
1591+ }
1592+ }
1593+
15661594 if let Some ( metadata) = self . discover_oauth_server_via_resource_metadata ( ) . await ? {
15671595 return Ok ( AuthorizationMetadataResolution {
15681596 metadata,
@@ -1584,45 +1612,6 @@ impl AuthorizationManager {
15841612 } )
15851613 }
15861614
1587- /// Resolve authorization server metadata starting from the
1588- /// `WWW-Authenticate` challenge of a real request's 401 response — the
1589- /// reactive discovery path, matching the TypeScript and Python SDKs.
1590- ///
1591- /// Seeds scope selection with the challenge's `scope` hint and prefers
1592- /// the challenge's `resource_metadata` URL; falls back to
1593- /// [`resolve_metadata`](Self::resolve_metadata) when the challenge is
1594- /// `None` or carries no usable metadata pointer.
1595- pub async fn resolve_metadata_from_challenge (
1596- & self ,
1597- www_authenticate : Option < & str > ,
1598- ) -> Result < AuthorizationMetadataResolution , AuthError > {
1599- let Some ( www_authenticate) = www_authenticate else {
1600- return self . resolve_metadata ( ) . await ;
1601- } ;
1602- let params = WWWAuthenticateParams :: parse ( www_authenticate, & self . base_url ) ;
1603-
1604- self . reset_initial_scopes ( ) . await ;
1605- self . record_initial_challenge_scope ( Some ( & params) ) . await ;
1606- self . record_challenge_scope ( & params) . await ;
1607-
1608- if let Some ( resource_metadata_url) = & params. resource_metadata_url
1609- && let Some ( metadata) = self
1610- . discover_oauth_server_from_resource_metadata_url ( resource_metadata_url)
1611- . await ?
1612- {
1613- return Ok ( AuthorizationMetadataResolution {
1614- metadata,
1615- source : AuthorizationMetadataSource :: ProtectedResourceMetadata ,
1616- } ) ;
1617- }
1618-
1619- self . resolve_metadata_inner ( ) . await
1620- }
1621-
1622- async fn reset_initial_scopes ( & self ) {
1623- * self . initial_scopes . write ( ) . await = InitialScopeState :: default ( ) ;
1624- }
1625-
16261615 async fn record_initial_challenge_scope ( & self , params : Option < & WWWAuthenticateParams > ) {
16271616 let mut initial_scopes = self . initial_scopes . write ( ) . await ;
16281617 if initial_scopes. challenge_scopes . is_none ( ) {
0 commit comments