Here is the problem and I don't think there is a solution. A very glaring error if HubSpot missed this.
Let's say my HubSpot Integration company made an AwesomeApp in my developer account. My company gets two customers for AwesomeApp, Customer A and Customer B. Each customer has an Installer (this is where the doc is very weak, the OAuth "user" is not an end user, not a salesperson, the user is acting in the role as an installer).
Installer A uses Awesome App's install url to install the app in Customer A's HubSpot account. The install url is pointed to my AWS Lambda function which gets a code representing the install during the first step and an auth+refresh token, representing creds for the installer for the second step.
Note that the auth token and the refresh token represent Installer A. Installer A has the rights to scopes for Customer A that they approve during install.
Awesome App's Lambda function stores the install code, the refresh token and access_token from Customer A to do work later for Customer A, on behalf of Installer A, since the refresh/access tokens belong to the Installer A
Installer B then installs Awesome App. The Lambda stores a second triad of code/access token/refresh token for Customer B.
Awesome App adds a Make Awesome Deal button to the HubSpot UI. The app is so awesome two users click on the Make Awesome Deal button at the same time, one user from Customer A the other from Customer B. Each from two different installs.
The click on the Make Awesome Deal button is sent to another Lambda function. The two calls from Customer A and Customer B race to this one function. When the function processes the first call, which access token should the function use? (Or if it has expired, which refresh token should the function use?)
The call gets the dealId, user ID, email and portalId. Can any of these be tied back to the install code or refresh token? Using one token gets data, using the other token gets a 404 (the object is in the other customers HubSpot customer account).