javaoauthoauth-2.0oltuexact-online

Token request on Exact Online not returning access token


I have been trying to use OAuth 2.0 to connect to Exact Online. We tend to focus on Java-applications and sadly Exact doesn't have documentation/examples/support for Java.

I was able to do the authentication request but for the token request I'm having some trouble. My code:

OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
        code = oar.getCode();

        OAuthClientRequest oAuthRequest;
        try {
            oAuthRequest = OAuthClientRequest
                    .tokenLocation("https://start.exactonline.be/api/oauth2/token")
                    .setGrantType(GrantType.AUTHORIZATION_CODE)
                    .setClientId(CLIENT_ID)
                    .setClientSecret(CLIENT_SECRET)
                    .setRedirectURI(REDIRECT_URI)
                    .setCode(code)
                    .buildQueryMessage();


            OAuthClient client = new OAuthClient(new URLConnectionClient());

            OAuthJSONAccessTokenResponse oauthResponse = client.accessToken(oAuthRequest, OAuth.HttpMethod.POST);
        }

I've looked around but all the answers I've found didn't solve the problem.

I always get 1 of these ProblemExceptions:

Token request failed: unsupported_response_type, Invalid response! Response body is not application/json encoded

Token request failed: invalid_request, Missing parameters: access_token

I was hoping anyone has prior experience dealing with exact online, any help is appreciated.


Solution

  • Solution was to use an older version of the Oltu library. Using 0.31 works, but 1.0.1 does not. Strange behavior but maybe this will help someone in the future.