tokenUri.addParameter(TOKEN_PARAMETER_CLIENT_SECRET, clientSecret);
tokenUri.addParameter(TOKEN_PARAMETER_CODE, scopeContext.getAuthenticationCode());
tokenUri.addParameter(TOKEN_PARAMETER_GRANT_TYPE, TOKEN_PARAMETER_GRANT_TYPE_VALUE);
tokenUri.addParameter(TOKEN_PARAMETER_REDIRECT_URI, scopeContext.getRedirectUri().toString());
final Request request;
try {
request = Request.Post(tokenUriString)
.bodyString(tokenUri.build().getQuery(), ContentType.APPLICATION_FORM_URLENCODED)
;
} catch (URISyntaxException e) {
throw new RuntimeException("Bad authorization URL for provided client and callback.", e);
}
final TokenServiceResponse token;
final Response response;
try {
response = request.execute();
final String responseContent = response.returnContent().asString();
token = mapper.readValue(responseContent, TokenServiceResponse.class);
} catch (JsonParseException e) {
throw new RuntimeException("Infusionsoft's protocol seemingly has changed. Invalid Token service response.", e);