@@ -108,7 +108,7 @@ func write401(w http.ResponseWriter, wwwAuthenticateHeader, errorType, message s
108108// - If ValidateToken is set, the exchanged token is then used against the Kubernetes API Server for TokenReview.
109109//
110110// see TestAuthorizationOidcTokenExchange
111- func AuthorizationMiddleware (staticConfig * config.StaticConfig , oidcProvider * oidc.Provider , verifier KubernetesApiTokenVerifier ) func (http.Handler ) http.Handler {
111+ func AuthorizationMiddleware (staticConfig * config.StaticConfig , oidcProvider * oidc.Provider , verifier KubernetesApiTokenVerifier , httpClient * http. Client ) func (http.Handler ) http.Handler {
112112 return func (next http.Handler ) http.Handler {
113113 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
114114 if r .URL .Path == healthEndpoint || slices .Contains (WellKnownEndpoints , r .URL .EscapedPath ()) {
@@ -159,7 +159,11 @@ func AuthorizationMiddleware(staticConfig *config.StaticConfig, oidcProvider *oi
159159 if err == nil && sts .IsEnabled () {
160160 var exchangedToken * oauth2.Token
161161 // If the token is valid, we can exchange it for a new token with the specified audience and scopes.
162- exchangedToken , err = sts .ExternalAccountTokenExchange (r .Context (), & oauth2.Token {
162+ ctx := r .Context ()
163+ if httpClient != nil {
164+ ctx = context .WithValue (ctx , oauth2 .HTTPClient , httpClient )
165+ }
166+ exchangedToken , err = sts .ExternalAccountTokenExchange (ctx , & oauth2.Token {
163167 AccessToken : claims .Token ,
164168 TokenType : "Bearer" ,
165169 })
0 commit comments