Hi everyone,
I’m building a HubSpot app using OAuth 2.0 and I want to restrict the installation of my app to only a specific set of HubSpot portals (identified by portalId). These portal IDs are stored in my backend DB (e.g., only clients who have onboarded with us).
Here’s the issue I’m facing:
- When the user installs the app and is redirected to my redirect_uri, I receive the code parameter.
- After exchanging the code for an access token using /oauth/v1/token, I can call the Get access token details (metadata) API to get the hub_id (portal ID).
- However, by this time, the app is already installed and authorized in that portal.
What I want to do is:
Prevent the app from connecting to portals not present in my allowlist
Only allow users from known portalIds to complete the OAuth flow and connect my app
Challenge:
Since the portalId is only available after token exchange, is there a secure way to check the portalId earlier in the flow (ideally before exchanging the code)?
Any guidance, recommended practices, or creative workarounds would be much appreciated!
Thanks in advance!