avaje/avaje-http-client

ENH: Add Basic Authentication support - BasicAuthIntercept

rbygrave opened this issue · 0 comments

So to add basic authentication on every request sent add the BasicAuthIntercept like below:

Example

Where the username is rob and the password is bot ... create and register the BasicAuthIntercept like:

  public static HttpClientContext client() {

    BasicAuthIntercept basicAuthIntercept = new BasicAuthIntercept("rob", "bot")

    return HttpClientContext.newBuilder()
      .withBaseUrl(baseUrl)
      .withRequestListener(new RequestLogger())
      .withBodyAdapter(new JacksonBodyAdapter(new ObjectMapper()))
      
      .withRequestIntercept(basicAuthIntercept)     <!--  HERE !!!
      .build();
  }