OAuth reauthentication?

Hey there,

I’m trying to build a bit of resillency in my Hubspot app by catching the “MISSING_SCOPES” error and prompting the user to reauthorize—which would happen if I expand the functionality of the app to require additional oauth 2 scopes.

As I’m building this I don’t see a way to pass the hubspot portal ID during the authentication flow, which poses 2 problems:

1) They could accidentally chose the wrong portal, and

2) We need to match the new key to their existing team on the way back.

Is there a way to match an existing Hubspot account on the frontend as a reauth request or is it always the case that if the token granted doesn’t have the appropriate scopes they need to auth again from scratch?
If that’s the case I can pass their existing team id and portal id in the scope and redo their token (and, check that they didn’t pick a different team!), but wondering if there’s a way to allow a user to redo an existing token instead of starting from scratch.

Thanks!

-Brian

Hi, @BSierakowski :waving_hand:

Thanks for your question. Based on the OAuth and Token management documentation, I don’t see a way to pass portal IDs this way.

I know myself and our community would be interested to hear how you got this worked out – no matter if you took a different route or if you found a solution that got you “close enough”. And we’ll leave this here in case our community members have any feedback for you.

Best,

Jaycee

Ah, yes, I hate it when I find a post that explains my problem and they just respond with “nevermind, I got it” :joy:.

I appreciate you taking a look, I came to the same conclusion, and I think it’s by design that you can’t expand the scopes on a given token. If you change your scopes, a new token must be created, so I made a parallel code path to “authorization” called “reauthorization.”

The main difference is that I have a different `redirect_uri` and pass the `state` param in addition to client_id and scope. In the state param I include the user’s `team_id`, which is their ID in our database, and their portal id.
When the user successfully completes the oauth2 process they come back to the different redirect_uri I verify that the portal_id coming back from the oauth2 process matches the portal_id we have for that team. If not, we let them know that they picked the wrong team to reauth, and if it does match we process the new oauth token in the same way we do a “new” token.
Hope that makes sense—happy to provide more info if that’d be useful to the community!