66 "encoding/json"
77 "fmt"
88 "net/http"
9+ "net/url"
910 "time"
1011)
1112
@@ -18,22 +19,62 @@ type TokenFetcher struct {
1819 RefreshToken string
1920 SkipSSLValidation bool
2021 UserAgent string
22+ ProxyAuthConfig ProxyAuthConfig
2123}
2224
23- func NewTokenFetcher (endpoint , refreshToken string , skipSSLValidation bool , userAgent string ) * TokenFetcher {
24- return & TokenFetcher {endpoint , refreshToken , skipSSLValidation , userAgent }
25+ func NewTokenFetcher (endpoint , refreshToken string , skipSSLValidation bool , userAgent string , proxyAuthConfig ProxyAuthConfig ) * TokenFetcher {
26+ return & TokenFetcher {endpoint , refreshToken , skipSSLValidation , userAgent , proxyAuthConfig }
2527}
2628
2729func (t TokenFetcher ) GetToken () (string , error ) {
28- httpClient := & http.Client {
29- Timeout : 60 * time .Second ,
30- Transport : & http.Transport {
30+ var transport http.RoundTripper
31+ var err error
32+
33+ // If proxy authentication is configured, use it; otherwise use standard transport
34+ if t .ProxyAuthConfig .AuthType != "" {
35+ // Create base transport
36+ baseTransport := & http.Transport {
37+ TLSClientConfig : & tls.Config {
38+ InsecureSkipVerify : t .SkipSSLValidation ,
39+ },
40+ }
41+
42+ // Parse proxy URL
43+ if t .ProxyAuthConfig .ProxyURL == "" {
44+ return "" , fmt .Errorf ("proxy URL is required when proxy authentication is specified" )
45+ }
46+ proxyURL , err := url .Parse (t .ProxyAuthConfig .ProxyURL )
47+ if err != nil {
48+ return "" , fmt .Errorf ("failed to parse proxy URL: %w" , err )
49+ }
50+ baseTransport .Proxy = http .ProxyURL (proxyURL )
51+
52+ // Create authenticator
53+ authenticator , err := NewProxyAuthenticator (t .ProxyAuthConfig )
54+ if err != nil {
55+ return "" , fmt .Errorf ("failed to create proxy authenticator: %w" , err )
56+ }
57+
58+ // Wrap transport with proxy authentication
59+ transport , err = NewProxyAuthTransport (baseTransport , authenticator )
60+ if err != nil {
61+ return "" , fmt .Errorf ("failed to initialize proxy authentication: %w" , err )
62+ }
63+ } else {
64+ // Use standard transport with environment proxy support
65+ transport = & http.Transport {
3166 TLSClientConfig : & tls.Config {
3267 InsecureSkipVerify : t .SkipSSLValidation ,
3368 },
3469 Proxy : http .ProxyFromEnvironment ,
35- },
70+ }
71+ }
72+
73+ httpClient := & http.Client {
74+ Timeout : 60 * time .Second ,
75+ Transport : transport ,
3676 }
77+
3778 body := AuthBody {RefreshToken : t .RefreshToken }
3879 b , err := json .Marshal (body )
3980 if err != nil {
0 commit comments