Get OAuth 2.0 Access Token and Refresh Tokens failue

oauth

#1

Hi,

After the first step I am redirected to Hubspot and approve the app, I am then redirected by to my server and I am trying to create a server to server OAuth request to get access token and refresh token:

https://api.hubapi.com/oauth/v1/token?code=CODE&grant_type=authorization_code&client_secret=MY_CLIENT_SECRET&redirect_uri=https%3A%2F%2Flocal.example.com%2Fhubspot-connect&client_id=MY_CLIENT_ID

I followed the documentation from:

However this request fails with error:
org.apache.oltu.oauth2.common.exception.OAuthProblemException: invalid_request, Missing parameters: access_token

Can you please help me to figure out what I am doing wrong? I am using java apache library to generate this request, it is getting a bit urgent for me and I don’t manage to solve this issue.

Thank you,
Eli


#2

Hi Everyone,

Just for a reference, in case you are using Apache Oltu as an OAuth library:

At first I executed:

OAuthClientRequest oAuthClientRequest =
                    OAuthClientRequest
                        .tokenLocation(tokenLocation)
                        .setGrantType(GrantType.AUTHORIZATION_CODE)
                        .setClientId(clientId)
                        .setClientSecret(clientSecret)
                        .setRedirectURI(redirectUrl)
                        .setCode(code)
                        .buildQueryMessage();

Just replaced buildQueryMessage() with --> buildBodyMessage()


#3

@Eli_A What is your redirect Uri and what error you are receiving?