@@ -16,6 +16,7 @@ import au.com.dius.pact.core.support.jsonObject
16
16
import au.com.dius.pact.core.support.unwrap
17
17
import com.google.common.net.UrlEscapers
18
18
import io.github.oshai.kotlinlogging.KLogging
19
+ import org.apache.hc.client5.http.auth.AuthScope
19
20
import org.apache.hc.client5.http.classic.methods.HttpGet
20
21
import org.apache.hc.client5.http.classic.methods.HttpPost
21
22
import org.apache.hc.client5.http.classic.methods.HttpPut
@@ -225,18 +226,19 @@ open class HalClient @JvmOverloads constructor(
225
226
logger.warn { " Authentication options needs to be either an instance of Auth or a list of values, ignoring." }
226
227
}
227
228
val uri = URI (baseUrl)
228
- val result = HttpClient .newHttpClient(options[" authentication" ], uri, this .maxPublishRetries,
229
+ val (client, credentialsProvider) = HttpClient .newHttpClient(options[" authentication" ], uri, this .maxPublishRetries,
229
230
this .publishRetryInterval, config.insecureTLS)
230
- httpClient = result.first
231
+ httpClient = client
231
232
232
233
if (System .getProperty(PREEMPTIVE_AUTHENTICATION ) == " true" ) {
233
234
val targetHost = HttpHost (uri.scheme, uri.host, uri.port)
234
235
logger.warn { " Using preemptive basic authentication with the pact broker at $targetHost " }
235
236
val authCache = BasicAuthCache ()
236
237
val basicAuth = BasicScheme ()
237
- authCache.put(targetHost, basicAuth)
238
238
httpContext = HttpClientContext .create()
239
- httpContext!! .credentialsProvider = result.second
239
+ httpContext!! .credentialsProvider = credentialsProvider
240
+ basicAuth.initPreemptive(credentialsProvider!! .getCredentials(AuthScope (uri.host, uri.port), httpContext))
241
+ authCache.put(targetHost, basicAuth)
240
242
httpContext!! .authCache = authCache
241
243
}
242
244
}
0 commit comments