Overview
The HubSpot Form Builder uses OAuth 2.0 to securely connect to your HubSpot account. This guide walks you through creating and configuring a HubSpot OAuth app.OAuth 2.0 provides secure, token-based authentication without exposing your credentials. The Form Builder stores access tokens temporarily in memory.
Creating a HubSpot OAuth App
Navigate to HubSpot Settings
Log into your HubSpot account and go to Settings → Integrations → Private Apps.
Create New App
Click “Create a private app” to start the setup process.Provide a descriptive name for your app, such as “Form Builder OAuth” or “Multistep Form Builder”.
Configure Required Scopes
The Form Builder requires the following scopes to function properly:
forms- Access to read HubSpot forms and their metadatacontent- Access to CMS content for module deploymentforms-uploaded-files- Access to file uploads within forms
Set Redirect URI
Add your OAuth callback URL to the Redirect URIs section:For local development:For production/tunnels:
The redirect URI must match exactly with the value in your
.env file, including the protocol (http/https) and trailing path.Environment Configuration
Configure your backend server with the OAuth credentials.Backend Environment Variables
Create or updatemain/server/.env:
The
HUBSPOT_SCOPES variable must match the scopes you selected when creating the app. Multiple scopes are separated by spaces.Frontend Environment Variables
Create or updatemain/frontend/.env:
OAuth Flow Implementation
The Form Builder implements the standard OAuth 2.0 authorization code flow:1. Authorization Request
When a user clicks “Connect to HubSpot”, the app generates a secure state token and redirects to HubSpot:- Client ID
- Redirect URI
- Required scopes
- Random state parameter (prevents CSRF attacks)
2. Token Exchange
After the user authorizes the app, HubSpot redirects back with an authorization code. The server exchanges this code for access and refresh tokens:3. Token Storage
Tokens are stored in-memory for the session:Security Considerations
State Parameter
The OAuth flow uses a cryptographically random state parameter to prevent CSRF attacks:Environment Variables
Never commit.env files to version control:
HTTPS in Production
Troubleshooting
”Missing env var” Error
If you see this error, ensure all required environment variables are set:HUBSPOT_CLIENT_IDHUBSPOT_CLIENT_SECRETHUBSPOT_REDIRECT_URIHUBSPOT_SCOPES
”Invalid state or code” Error
This error occurs when:- The state parameter doesn’t match (possible CSRF attempt)
- The authorization code is missing
- The redirect URI doesn’t match exactly
HUBSPOT_REDIRECT_URI matches the value configured in HubSpot.
”Token exchange failed” Error
Common causes:- Incorrect Client ID or Client Secret
- Mismatched redirect URI
- Expired authorization code (codes expire after ~60 seconds)
Next Steps
Connecting to HubSpot
Learn how to connect the Form Builder to your HubSpot account
HubSpot API Reference
Explore the API endpoints used by the Form Builder
