@@ -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
@@ -608,6 +625,8 @@ pub struct BaseClient {
608625 allow_insecure_host : Vec < TrustedHost > ,
609626 /// The number of retries to attempt on transient errors.
610627 retries : u32 ,
628+ /// Global authentication cache for a uv invocation to share credentials across uv clients.
629+ credentials_cache : Arc < CredentialsCache > ,
611630}
612631
613632#[ derive( Debug , Clone , Copy ) ]
@@ -659,6 +678,10 @@ impl BaseClient {
659678 }
660679 builder. build_with_max_retries ( self . retries )
661680 }
681+
682+ pub fn credentials_cache ( & self ) -> & CredentialsCache {
683+ & self . credentials_cache
684+ }
662685}
663686
664687/// Wrapper around [`ClientWithMiddleware`] that manages redirects.
0 commit comments