Source:
public OAuth2AccessToken getOAuth2AccessToken() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException { String signedJwt = createSignedJWT(clientConfiguration); String scope = String.join(" ", clientConfiguration.getScopes()); MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded"); RequestBody body = RequestBody.create(mediaType, ""); OkHttpClient client = new OkHttpClient().newBuilder().build(); Request accessTokenRequest = new Request.Builder() .url(clientConfiguration.getBaseUrl() + "/oauth2/v1/token" + "?grant_type=client_credentials" + "&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer" + "&client_assertion=" + signedJwt + "&scope=" + scope) .method(HttpMethod.POST.name(), body) .addHeader("Accept", "application/json") .addHeader("Content-Type", "application/x-www-form-urlencoded") .build(); Response accessTokenResponse = client.newCall(accessTokenRequest).execute(); if (accessTokenResponse != null && accessTokenResponse.body() != null) { Reader reader = new InputStreamReader(accessTokenResponse.body().byteStream(), StandardCharsets.UTF_8); if (accessTokenResponse.isSuccessful()) { log.debug("Access token request was successful"); return objectMapper.readValue(reader, OAuth2AccessToken.class); } else { ErrorResponse errorResponse = objectMapper.readValue(reader, ErrorResponse.class); log.debug("Access token request failed with error {}", errorResponse); if (!Strings.isEmpty(errorResponse.getError()) || !Strings.isEmpty(errorResponse.getErrorDescription())) { throw new HttpException("Received HTTP " + accessTokenResponse.code() + " response from Authorization Server. error - " + errorResponse.getError() + ", error description - " + errorResponse.getErrorDescription()); } else { throw new HttpException("Received HTTP " + accessTokenResponse.code() + " response from Authorization Server"); } } } else { throw new HttpException("Could not retrieve access token from Authorization Server"); } }

Target:
public OAuth2AccessToken getOAuth2AccessToken() throws IOException, InvalidKeyException, OAuth2TokenRetrieverException { log.debug("Attempting to get OAuth2 access token for client id from {}", tokenClientConfiguration.getClientId(), tokenClientConfiguration.getBaseUrl() + TOKEN_URI); String signedJwt = createSignedJWT(); String scope = String.join(" ", tokenClientConfiguration.getScopes()); try { ExtensibleResource accessTokenResponse = tokenClient.http() .addHeaderParameter("Accept", MediaType.APPLICATION_JSON_VALUE) .addHeaderParameter("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE) .addQueryParameter("grant_type", "client_credentials") .addQueryParameter("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer") .addQueryParameter("client_assertion", signedJwt) .addQueryParameter("scope", scope) .post(TOKEN_URI, ExtensibleResource.class); OAuth2AccessToken oAuth2AccessToken = new OAuth2AccessToken(); oAuth2AccessToken.setTokenType(accessTokenResponse.getString(OAuth2AccessToken.TOKEN_TYPE_KEY)); oAuth2AccessToken.setExpiresIn(accessTokenResponse.getInteger(OAuth2AccessToken.EXPIRES_IN_KEY)); oAuth2AccessToken.setAccessToken(accessTokenResponse.getString(OAuth2AccessToken.ACCESS_TOKEN_KEY)); oAuth2AccessToken.setScope(accessTokenResponse.getString(OAuth2AccessToken.SCOPE_KEY)); log.debug("Got OAuth2 access token for client id from {}", tokenClientConfiguration.getClientId(), tokenClientConfiguration.getBaseUrl() + TOKEN_URI); return oAuth2AccessToken; } catch (ResourceException e) { DefaultError defaultError = (DefaultError) e.getError(); String errorMessage = defaultError.getString(OAuth2AccessToken.ERROR_KEY); String errorDescription = defaultError.getString(OAuth2AccessToken.ERROR_DESCRIPTION); defaultError.setMessage(errorMessage + " - " + errorDescription); throw new OAuth2HttpException(defaultError, e, e.getStatus() == 401); } catch (Exception e) { throw new OAuth2TokenRetrieverException("Exception while trying to get " + "OAuth2 access token for client id " + tokenClientConfiguration.getClientId(), e); } }