code: private BasicCredentialsProvider getCredentialsProvider() {
          return new BasicCredentialsProvider() {
              private Set<AuthScope> authAlreadyTried = Sets.newHashSet();
  
              @Override
              public Credentials getCredentials(AuthScope authscope) {
                  if (authAlreadyTried.contains(authscope)) {
                      return null;
                  }
                  authAlreadyTried.add(authscope);
                  return super.getCredentials(authscope);
              }
          };
      }
docs: With this impl, it only returns the same credentials once. Otherwise it's possible that a loop will occur.
  When server returns status code 401, the HTTP client provides the same credentials forever.
  Since we create a new HTTP client for every request, we can handle it this way.