I'm using JettyHttp Client to call external API code below:
object Test extends App {
val client = new HttpClient(new SslContextFactory.Client())
client.start()
val response = client.POST("https://xxx")
.header("authorization","bearer LOL")
.content(new StringContentProvider("{}"))
.send()
println("xd")
}
and the result is
Exception in thread "main" java.util.concurrent.ExecutionException: org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: Authentication challenge without WWW-Authenticate header
this is fine - works like described here - https://web.archive.org/web/20191231154352/http://www.eclipse.org:80/jetty/documentation/current/http-client-authentication.html
But I also tried this:
object Test extends App {
val client = new HttpClient(new SslContextFactory.Client())
client.getAuthenticationStore.addAuthenticationResult(new Authentication.Result {
override def getURI: URI = URI.create("https://xxx")
override def apply(request: Request): Unit = request.header("authorization", "bearer lol")
})
client.start()
val response = client.POST("https://xxx")
.content(new StringContentProvider("{}"))
.send()
println("xd")
}
and still the same result. I cannot enforce the external server to return proper WWW-Authenticate header in response with 401. Can I make the Jetty client somehow to send just the request with Authorization header without this first 401 request? The external API works fine - I can curl the API and get the proper answer.