@@ -3,22 +3,20 @@ use std::sync::{Arc, LazyLock};
33use anyhow:: { anyhow, format_err} ;
44use http:: { Extensions , StatusCode } ;
55use reqwest:: { Request , Response } ;
6- use reqwest_middleware:: { ClientWithMiddleware , Error , Middleware , Next } ;
6+ use reqwest_middleware:: { Error , Middleware , Next } ;
77use tokio:: sync:: Mutex ;
88use tracing:: { debug, trace, warn} ;
99
1010use uv_netrc:: Netrc ;
1111use uv_preview:: { Preview , PreviewFeature } ;
1212use uv_redacted:: DisplaySafeUrl ;
1313use uv_static:: EnvVars ;
14- use uv_warnings:: owo_colors:: OwoColorize ;
1514
1615use crate :: providers:: {
1716 AzureEndpointProvider , GcsEndpointProvider , HuggingFaceProvider , S3EndpointProvider ,
1817} ;
19- use crate :: pyx:: { DEFAULT_TOLERANCE_SECS , PyxTokenStore } ;
2018use crate :: {
21- AccessToken , CredentialsCache , KeyringProvider ,
19+ CredentialsCache , KeyringProvider ,
2220 cache:: FetchUrl ,
2321 credentials:: {
2422 Authentication , AuthenticationError , Credentials , CredentialsFromUrlError , Username ,
@@ -143,15 +141,6 @@ impl TextStoreMode {
143141 }
144142}
145143
146- #[ derive( Debug , Clone ) ]
147- enum TokenState {
148- /// The token state has not yet been initialized from the store.
149- Uninitialized ,
150- /// The token state has been initialized, and the store either returned tokens or `None` if
151- /// the user has not yet authenticated.
152- Initialized ( Option < AccessToken > ) ,
153- }
154-
155144#[ derive( Clone ) ]
156145enum S3CredentialState {
157146 /// The S3 credential state has not yet been initialized.
@@ -194,12 +183,6 @@ pub struct AuthMiddleware {
194183 /// Set all endpoints as needing authentication. We never try to send an
195184 /// unauthenticated request, avoiding cloning an uncloneable request.
196185 only_authenticated : bool ,
197- /// The base client to use for requests within the middleware.
198- base_client : Option < ClientWithMiddleware > ,
199- /// The pyx token store to use for persistent credentials.
200- pyx_token_store : Option < PyxTokenStore > ,
201- /// Tokens to use for persistent credentials.
202- pyx_token_state : Mutex < TokenState > ,
203186 /// Cached S3 credentials to avoid running the credential helper multiple times.
204187 s3_credential_state : Mutex < S3CredentialState > ,
205188 /// Cached GCS credentials to avoid running the credential helper multiple times.
@@ -225,9 +208,6 @@ impl AuthMiddleware {
225208 cache : Arc :: new ( CredentialsCache :: default ( ) ) ,
226209 indexes : Indexes :: new ( ) ,
227210 only_authenticated : false ,
228- base_client : None ,
229- pyx_token_store : None ,
230- pyx_token_state : Mutex :: new ( TokenState :: Uninitialized ) ,
231211 s3_credential_state : Mutex :: new ( S3CredentialState :: Uninitialized ) ,
232212 gcs_credential_state : Mutex :: new ( GcsCredentialState :: Uninitialized ) ,
233213 azure_credential_state : Mutex :: new ( AzureCredentialState :: Uninitialized ) ,
@@ -307,20 +287,6 @@ impl AuthMiddleware {
307287 self
308288 }
309289
310- /// Configure the [`ClientWithMiddleware`] to use for requests within the middleware.
311- #[ must_use]
312- pub fn with_base_client ( mut self , client : ClientWithMiddleware ) -> Self {
313- self . base_client = Some ( client) ;
314- self
315- }
316-
317- /// Configure the [`PyxTokenStore`] to use for persistent credentials.
318- #[ must_use]
319- pub fn with_pyx_token_store ( mut self , token_store : PyxTokenStore ) -> Self {
320- self . pyx_token_store = Some ( token_store) ;
321- self
322- }
323-
324290 /// Global authentication cache for a uv invocation to share credentials across uv clients.
325291 fn cache ( & self ) -> & CredentialsCache {
326292 & self . cache
@@ -428,18 +394,8 @@ impl Middleware for AuthMiddleware {
428394 . as_ref ( )
429395 . is_some_and ( |credentials| credentials. username ( ) . is_some ( ) ) ;
430396
431- // Determine whether this is a "known" URL.
432- let is_known_url = self
433- . pyx_token_store
434- . as_ref ( )
435- . is_some_and ( |token_store| token_store. is_known_url ( request. url ( ) ) ) ;
436-
437397 let must_authenticate = self . only_authenticated
438- || ( match auth_policy {
439- AuthPolicy :: Auto => is_known_url,
440- AuthPolicy :: Always => true ,
441- AuthPolicy :: Never => false ,
442- }
398+ || ( matches ! ( auth_policy, AuthPolicy :: Always )
443399 // Dependabot intercepts HTTP requests and injects credentials, which means that we
444400 // cannot eagerly enforce an `AuthPolicy` as we don't know whether credentials will be
445401 // added outside of uv.
@@ -551,19 +507,6 @@ impl Middleware for AuthMiddleware {
551507
552508 if let Some ( response) = response {
553509 Ok ( response)
554- } else if let Some ( store) = is_known_url
555- . then_some ( self . pyx_token_store . as_ref ( ) )
556- . flatten ( )
557- {
558- let domain = store
559- . api ( )
560- . domain ( )
561- . unwrap_or ( "pyx.dev" )
562- . trim_start_matches ( "api." ) ;
563- Err ( Error :: Middleware ( format_err ! (
564- "Run `{}` to authenticate uv with pyx" ,
565- format!( "uv auth login {domain}" ) . green( )
566- ) ) )
567510 } else {
568511 Err ( Error :: Middleware ( format_err ! (
569512 "Missing credentials for {url}"
@@ -809,45 +752,8 @@ impl AuthMiddleware {
809752 }
810753 }
811754
812- // If this is a known URL, authenticate it via the token store.
813- let credentials = if let Some ( credentials) = async {
814- let base_client = self . base_client . as_ref ( ) ?;
815- let token_store = self . pyx_token_store . as_ref ( ) ?;
816- if !token_store. is_known_url ( url) {
817- return None ;
818- }
819-
820- let mut token_state = self . pyx_token_state . lock ( ) . await ;
821-
822- // If the token store is uninitialized, initialize it.
823- let token = match * token_state {
824- TokenState :: Uninitialized => {
825- trace ! ( "Initializing token store for {url}" ) ;
826- let generated = match token_store
827- . access_token ( base_client, DEFAULT_TOLERANCE_SECS )
828- . await
829- {
830- Ok ( Some ( token) ) => Some ( token) ,
831- Ok ( None ) => None ,
832- Err ( err) => {
833- warn ! ( "Failed to generate access tokens: {err}" ) ;
834- None
835- }
836- } ;
837- * token_state = TokenState :: Initialized ( generated. clone ( ) ) ;
838- generated
839- }
840- TokenState :: Initialized ( ref tokens) => tokens. clone ( ) ,
841- } ;
842-
843- token. map ( Credentials :: from)
844- }
845- . await
846- {
847- debug ! ( "Found credentials from token store for {url}" ) ;
848- Some ( credentials)
849755 // Netrc support based on: <https://github.com/gribouille/netrc>.
850- } else if let Some ( credentials) = self . netrc . get ( ) . and_then ( |netrc| {
756+ let credentials = if let Some ( credentials) = self . netrc . get ( ) . and_then ( |netrc| {
851757 debug ! ( "Checking netrc for credentials for {url}" ) ;
852758 Credentials :: from_netrc (
853759 netrc,
0 commit comments