I have an app that has been in use for several years using OAuth, and haven’t since last year tried connecting to a different HubSpot target account. Now when I do I get this ‘redirect_uri doesn’t match’ error.
App is built using the hubspot/hubspot-php version 4.0.2 library, and I’m using the connection method described in the ReadME with the Factory method:
// Build URL for OAuth
$authUrl = \SevenShores\Hubspot\Utils\OAuth2::getAuthUrl(
$this->client_id,
$this->redirect_uri,
$this->client_scope_array,
[]
);
header('Location: ’ . $authUrl);
Then in the HS Dev panel for the app, previously there was no Redirect_URI entered, but it looks like that is now a requirement. So at first I was trying with my dev system which I was using a simple http://localhost/application/ URL and was still receiving the same error. Thought perhaps I needed to setup a self-signed name and SSL as that’s now required for anything other than ‘localhost’, set that up (ssl/site application.localdev) and tried that for a redirect_uri, but that didn’t make any difference, same error.
There are two differences in the HS documentation Auth URL samples redirect_uri values and mine (other than the destination).
(mine)
https://app.hubspot.com/oauth/#####/authorize?client\_id=abcdf####&
redirect_uri=https%3A%2F%2Fapplication.localdev%3Faction%3Doauth-callback
&scope=crm.lists.read%20crm.lists.write …
(HS typical example)
redirect_uri=https://www.example.com/auth-callback
&scope= …
First is the encoding the HubSpot-PHP library is encoding (correctly I believe) the ‘://’, ‘?’, and ‘=’ in my redirect_uri (‘https%3A%2F%2Fapplication.localdev%3F..’.) where as the examples only escape the spaces in the ‘scope’ value (examples are ‘https://www.example…’). There is a 5x version of hubspot-php, looking that the static method for generating the Auth URL while improved (it doesn’t add empty optional query string keys) uses the same encoding so ‘redirect_url=https://anything’ will still be passed as ‘redirect_url=https%3A%2F%2Fanything’ in the auth url.
Second difference is my callback redirect_uri includes a query string.
In the HubSpot dev control panel Auth screen, are redirect_uri’s to include the query string? Assume it does but tried with and without, and with and without trailing slashes (note “https://” is displayed before the entry field, so assume that’s to mean not include in the input entry):
https:// “application.localdev”
https:// “application.localdev/”
https:// “application.localdev/?action=auth-callback”
https:// “application.localdev?action=auth-callback”
https:// “localhost/application”
https:// “localhost/application/”
https:// “localhost/application/action=auth-callback”
and still get the error after selecting an account to connect: redirect_uri doesn’t match the client registered redirect_uri.
- What might I be missing?
- Am I at least correct the message ‘redirect_uri doesn’t match client regirstered redirect_uri’ to mean the passed redirect_uri value in the Auth URL is not being found in the list of redirect_uri’s in the app’s Auth screen?
- The listed redirect_uri in the Auth screen need to be exact path AND query string to match what will be passed in the Auth URL redirect_uri value?
- Should not the redirect_url value in the auth url encoding to be ‘encodeURICompontent’ equivalent (“http%3A%2F%2Fwww.example…”)?