0

Why does the following results in an "Unauthorized" response:

 webClient
            .getAbs("http://hello.com")
            .basicAuthentication("user", "pw")
            .rxSend()
            .subscribe();

Whereas the following works fine:

 webClient
                .getAbs("http://hello.com")
                .putHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("user:pw".getBytes()) )
                .rxSend()
                .subscribe();
yN.
  • 1,847
  • 5
  • 30
  • 47

2 Answers2

2

This is the implementation for basicAuthentication

    Buffer buff = Buffer.buffer().appendBuffer(id).appendString("-").appendBuffer(password);
    String credentials =  new String(Base64.getEncoder().encode(buff.getBytes()));
    return putHeader(HttpHeaders.AUTHORIZATION.toString(), "Basic " + credentials);

It puts user-pw not user:pw.

rjeeb
  • 461
  • 3
  • 11
  • You are totally right! This seems to be a bug since the java doc of the method says otherwise. – yN. Jul 22 '19 at 08:42
  • 1
    This has been fixed and is available since version 3.7 https://github.com/vert-x3/vertx-web/commit/a7def14fba4589c1b112489d837658455f8f4301#diff-6d762e73191a4cf2bb08e92dac3ca550 – Pendula Jul 23 '19 at 11:39
0

The method description conflicts with the current implementation, since it says "joined by a colon", so I guess this is a bug. Im currently using version 3.6.3.

  /**
   * Configure the request to perform basic access authentication.
   * <p>
   * In basic HTTP authentication, a request contains a header field of the form 'Authorization: Basic &#60;credentials&#62;',
   * where credentials is the base64 encoding of id and password joined by a colon.
   * </p>
   *
   * @param id the id
   * @param password the password
   * @return a reference to this, so the API can be used fluently
   */
  @Fluent
  HttpRequest<T> basicAuthentication(String id, String password);
yN.
  • 1,847
  • 5
  • 30
  • 47