400 Error - missing or unknown auth code


#1

In my Production Rails app I seem to have trouble getting the refresh token I need. When I try to get the Auth code I get back "missing or unknown auth code" Any idea what I might be missing - happy to share more fields if needed. Note, on the redirect uri Im redirecting the page and grabbing the params "code" in the URL. Thanks!

   response = HTTParty.post('https://api.hubapi.com/oauth/v1/token',
  body: {
    grant_type: 'authorization_code',
    client_id: APP_CONFIG['hubspot_client_id'],
    client_secret: APP_CONFIG['hubspot_client_secret'],
    redirect_uri: Rails.application.routes.url_helpers.connect_hubspot_site_url(@site, protocol: 'https'),
  },
  headers: {
    "Content-Type" => "application/x-www-form-urlencoded;charset=utf-8"
  }
)

Response:

{ 
 "status"=>"BAD_AUTH_CODE",
 "message"=>"missing or unknown auth code",
 "correlationId"=>"7f6aed81-f215-4f32-8df9-2a04cdb270f6",
 "requestId"=>"25f6e32ec12344225400ed61b7052c7b"
}

#2

Hi @john1214,

Are you making this request after you've redirected and received the authorization code? You need to include the authorization code in your request to get the access/refresh tokens; I don't see the code present in the request body you included above.