- Sign in with Hubspot OAuth & generate JWT.
- All routes are protected with JWT.
- Public routes using
@Public
decorator.
-
Check Hubspot OAuth Docs
-
run the following command to create .env file
$ cp .env.example .env
-
Create a developer account
-
Create a hubspot app
-
Open the hubspot app page, then navigate to the "Auth" tab
-
Change the redirect url to be "http://localhost:3000/auth/hubspot/callback"
-
Add desired scopes
-
Save changes
-
Copy from hubspot app page to
.env
the following:Client ID
toHUBSPOT_CLIENT_ID
Client secret
toHUBSPOT_CLIENT_SECRET
Install URL(OAuth)
toHUBSPOT_AUTHORIZATION_URL
- one
Redirect URLs
toHUBSPOT_REDIRECT_URL
Selected scopes
toHUBSPOT_SCOPE
as a space separated string. Example: "crm.lists.read crm.objects.contacts.read"
-
Run the following commands to install & start the app:
$ yarn install # install dependencies $ yarn start:dev # run dev server
-
Navigate to http://localhost:3000/auth/sign-in and click on "sign in with Hubspot"
-
Click to Install the app, then you'll be redirected to a page that contains the access token.
-
send a GET request to http://localhost:3000/contacts with the access token in the authorization header prefixed with
Bearer
Route | Security | Description |
---|---|---|
/health-check
|
Public | Health check |
/auth/sign-in
|
Public | Show "sign in with hubspot" button |
/auth/hubspot/sign-in
|
Public | Redirect to hubspot authentication page |
/auth/hubspot/callback
|
Public |
Returns access token used to request protected routes.
Hubspot will redirect to this route (after successful authentication) with code in url query. |
/contacts
|
Protected | List contacts in Hubspot. |