@@ -28,7 +28,7 @@ use tracing::{debug, trace};
2828use url:: ParseError ;
2929use url:: Url ;
3030
31- use uv_auth:: { AuthMiddleware , Credentials , Indexes , PyxTokenStore } ;
31+ use uv_auth:: { AuthMiddleware , Credentials , CredentialsCache , Indexes , PyxTokenStore } ;
3232use uv_configuration:: { KeyringProviderType , TrustedHost } ;
3333use uv_fs:: Simplified ;
3434use uv_pep508:: MarkerEnvironment ;
@@ -78,6 +78,8 @@ pub struct BaseClientBuilder<'a> {
7878 markers : Option < & ' a MarkerEnvironment > ,
7979 platform : Option < & ' a Platform > ,
8080 auth_integration : AuthIntegration ,
81+ /// Global authentication cache for a uv invocation to share credentials across uv clients.
82+ credentials_cache : Arc < CredentialsCache > ,
8183 indexes : Indexes ,
8284 timeout : Duration ,
8385 extra_middleware : Option < ExtraMiddleware > ,
@@ -136,6 +138,7 @@ impl Default for BaseClientBuilder<'_> {
136138 markers : None ,
137139 platform : None ,
138140 auth_integration : AuthIntegration :: default ( ) ,
141+ credentials_cache : Arc :: new ( CredentialsCache :: default ( ) ) ,
139142 indexes : Indexes :: new ( ) ,
140143 timeout : Duration :: from_secs ( 30 ) ,
141144 extra_middleware : None ,
@@ -147,7 +150,7 @@ impl Default for BaseClientBuilder<'_> {
147150 }
148151}
149152
150- impl BaseClientBuilder < ' _ > {
153+ impl < ' a > BaseClientBuilder < ' a > {
151154 pub fn new (
152155 connectivity : Connectivity ,
153156 native_tls : bool ,
@@ -166,9 +169,7 @@ impl BaseClientBuilder<'_> {
166169 ..Self :: default ( )
167170 }
168171 }
169- }
170172
171- impl < ' a > BaseClientBuilder < ' a > {
172173 /// Use a custom reqwest client instead of creating a new one.
173174 ///
174175 /// This allows you to provide your own reqwest client with custom configuration.
@@ -276,6 +277,20 @@ impl<'a> BaseClientBuilder<'a> {
276277 self
277278 }
278279
280+ pub fn credentials_cache ( & self ) -> & CredentialsCache {
281+ & self . credentials_cache
282+ }
283+
284+ /// See [`CredentialsCache::store_credentials_from_url`].
285+ pub fn store_credentials_from_url ( & self , url : & DisplaySafeUrl ) -> bool {
286+ self . credentials_cache . store_credentials_from_url ( url)
287+ }
288+
289+ /// See [`CredentialsCache::store_credentials`].
290+ pub fn store_credentials ( & self , url : & DisplaySafeUrl , credentials : Credentials ) {
291+ self . credentials_cache . store_credentials ( url, credentials) ;
292+ }
293+
279294 pub fn is_native_tls ( & self ) -> bool {
280295 self . native_tls
281296 }
@@ -324,6 +339,7 @@ impl<'a> BaseClientBuilder<'a> {
324339 dangerous_client,
325340 raw_dangerous_client,
326341 timeout,
342+ credentials_cache : self . credentials_cache . clone ( ) ,
327343 }
328344 }
329345
@@ -350,6 +366,7 @@ impl<'a> BaseClientBuilder<'a> {
350366 raw_client : existing. raw_client . clone ( ) ,
351367 raw_dangerous_client : existing. raw_dangerous_client . clone ( ) ,
352368 timeout : existing. timeout ,
369+ credentials_cache : existing. credentials_cache . clone ( ) ,
353370 }
354371 }
355372
@@ -554,6 +571,7 @@ impl<'a> BaseClientBuilder<'a> {
554571 match self . auth_integration {
555572 AuthIntegration :: Default => {
556573 let mut auth_middleware = AuthMiddleware :: new ( )
574+ . with_cache_arc ( self . credentials_cache . clone ( ) )
557575 . with_base_client ( base_client)
558576 . with_indexes ( self . indexes . clone ( ) )
559577 . with_keyring ( self . keyring . to_provider ( ) )
@@ -565,6 +583,7 @@ impl<'a> BaseClientBuilder<'a> {
565583 }
566584 AuthIntegration :: OnlyAuthenticated => {
567585 let mut auth_middleware = AuthMiddleware :: new ( )
586+ . with_cache_arc ( self . credentials_cache . clone ( ) )
568587 . with_base_client ( base_client)
569588 . with_indexes ( self . indexes . clone ( ) )
570589 . with_keyring ( self . keyring . to_provider ( ) )
@@ -608,6 +627,8 @@ pub struct BaseClient {
608627 allow_insecure_host : Vec < TrustedHost > ,
609628 /// The number of retries to attempt on transient errors.
610629 retries : u32 ,
630+ /// Global authentication cache for a uv invocation to share credentials across uv clients.
631+ credentials_cache : Arc < CredentialsCache > ,
611632}
612633
613634#[ derive( Debug , Clone , Copy ) ]
@@ -659,6 +680,10 @@ impl BaseClient {
659680 }
660681 builder. build_with_max_retries ( self . retries )
661682 }
683+
684+ pub fn credentials_cache ( & self ) -> & CredentialsCache {
685+ & self . credentials_cache
686+ }
662687}
663688
664689/// Wrapper around [`ClientWithMiddleware`] that manages redirects.
0 commit comments