public TokenResponse sendRequest(final boolean expectingIdToken) {
        final Invocation.Builder invocationBuilder = createWebTarget().request(MediaType.APPLICATION_JSON_TYPE);
        addBasicAuth(invocationBuilder);

        TokenResponse tokenResponse = null;
        try (Response response = doPost(invocationBuilder)) {
            if (HttpServletResponse.SC_OK == response.getStatus()) {
                final String json = response.readEntity(String.class);
                LOGGER.debug("response json:\n{}", json);
                tokenResponse = objectMapper.readValue(json, TokenResponse.class);
            } else {
                // Attempt to get content from the response, e.g. an error msg

                // NOTE: If you get a 500 here and are using KeyCloak, make sure the jersey client has
                // gzipEnabledForRequests: false
                // else you will see this error in the KeyCloak logs.
                // java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern
                // This may only be an issue for KeyCloak standalone.
                final String msg = getContent(response);
                throw new AuthenticationException("Received status '" +
                                                  response.getStatus() +
                                                  "' from " +
                                                  endpointUri + " :\n" + msg);
            }
        } catch (Exception e) {
            throw new AuthenticationException(
                    "Error requesting token from " + endpointUri + ": " + e.getMessage(), e);
        }

        if (tokenResponse == null) {
            throw new AuthenticationException("Null tokenResponse using url: " + endpointUri);
        } else if (expectingIdToken && tokenResponse.getIdToken() == null) {
            throw new AuthenticationException("Expecting '" +
                                              OpenId.ID_TOKEN +
                                              "' to be in response but it is absent. Using url: " + endpointUri);
        }

        return tokenResponse;
    }
Allows you do define client credentials that differ from those in {@link OpenIdConfiguration}
stroom-security/stroom-security-common-impl/src/main/java/stroom/security/common/impl/OpenIdTokenRequestHelper.java