Skip to content

Commit a0beb02

Browse files
MiciurashThangHuuVu
andauthoredSep 11, 2022
feat(providers): Add HubSpot Provider (#4633)
* Typos fix * Added HubSpot Provider * updates to profile * Update docs/docs/providers/hubspot.md Co-authored-by: Thang Vu <31528554+ThangHuuVu@users.noreply.github.com> * fixed typo and outsourced required fields * removing redirectURL from the provider config * replaced with "client_secret_post" client method Co-authored-by: Thang Vu <31528554+ThangHuuVu@users.noreply.github.com>
1 parent 5727c5f commit a0beb02

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed
 

‎SECURITY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you contact us regarding a serious issue:
1515

1616
The best way to report an issue is by contacting us via email at info@balazsorban.com, yo@ndo.dev, thvu@hey.com and me@iaincollins.com, or raise a public issue requesting someone get in touch with you via whatever means you prefer for more details. (Please do not disclose sensitive details publicly at this stage.)
1717

18-
> For less serious issues (e.g. RFC compliance for unsupported flows or potential issues that may cause a problem in the future) it is appropriate to submit these these publically as bug reports or feature requests or to raise a question to open a discussion around them.
18+
> For less serious issues (e.g. RFC compliance for unsupported flows or potential issues that may cause a problem in the future) it is appropriate to submit these publicly as bug reports or feature requests or to raise a question to open a discussion around them.
1919
2020
## Supported Versions
2121

‎docs/docs/providers/hubspot.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
id: hubspot
3+
title: HubSpot
4+
---
5+
6+
:::note
7+
HubSpot returns a limited amount of information on the token holder (see [docs](https://legacydocs.hubspot.com/docs/methods/oauth2/get-access-token-information)). One other issue is that the name and profile photo cannot be fetched through API as discussed [here](https://community.hubspot.com/t5/APIs-Integrations/Profile-photo-is-not-retrieved-with-User-API/m-p/325521).
8+
:::
9+
10+
## Documentation
11+
12+
https://developers.hubspot.com/docs/api/oauth-quickstart-guide
13+
14+
## Configuration
15+
16+
You need to have an APP in your Developer Account as described at https://developers.hubspot.com/docs/api/developer-tools-overview
17+
18+
## Options
19+
20+
The **HubSpot Provider** comes with a set of default options:
21+
22+
- [HubSpot Provider options](https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/hubspot.ts)
23+
24+
You can override any of the options to suit your own use case.
25+
26+
## Example
27+
28+
```js
29+
import HubspotProvider from "next-auth/providers/hubspot";
30+
...
31+
providers: [
32+
HubspotProvider({
33+
clientId: process.env.HUBSPOT_CLIENT_ID,
34+
clientSecret: process.env.HUBSPOT_CLIENT_SECRET
35+
})
36+
]
37+
...
38+
```
39+
40+
:::warning
41+
The **Redirect URL** under the **Auth** tab on the HubSpot App Settings page must match the callback url which would be http://localhost:3000/api/auth/callback/hubspot for local development. Only one callback URL per Client ID and Client Secret pair is allowed, so it might be easier to create a new app for local development then fiddle with the url changes.
42+
:::
43+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import type { OAuthConfig, OAuthUserConfig } from "."
2+
3+
interface HubSpotProfile extends Record<string, any> {
4+
5+
// TODO: figure out additional fields, for now using
6+
// https://legacydocs.hubspot.com/docs/methods/oauth2/get-access-token-information
7+
8+
user: string,
9+
user_id: string,
10+
11+
hub_domain: string,
12+
hub_id: string,
13+
}
14+
15+
16+
const HubSpotConfig = {
17+
authorizationUrl: "https://app.hubspot.com/oauth/authorize",
18+
tokenUrl: "https://api.hubapi.com/oauth/v1/token",
19+
profileUrl: "https://api.hubapi.com/oauth/v1/access-tokens"
20+
}
21+
22+
export default function HubSpot<P extends HubSpotProfile>(
23+
options: OAuthUserConfig<P>
24+
): OAuthConfig<P> {
25+
26+
return {
27+
id: "hubspot",
28+
name: "HubSpot",
29+
type: "oauth",
30+
31+
...HubSpotConfig,
32+
33+
authorization: {
34+
url: HubSpotConfig.authorizationUrl,
35+
params: {
36+
scope: "oauth",
37+
client_id: options.clientId,
38+
},
39+
40+
},
41+
client: {
42+
token_endpoint_auth_method: "client_secret_post",
43+
},
44+
token: HubSpotConfig.tokenUrl,
45+
userinfo: {
46+
url: HubSpotConfig.profileUrl,
47+
async request(context) {
48+
49+
const url = `${HubSpotConfig.profileUrl}/${context.tokens.access_token}`;
50+
51+
const response = await fetch(url, {
52+
headers: {
53+
"Content-Type": "application/json",
54+
},
55+
method: "GET",
56+
});
57+
58+
const userInfo = await response.json();
59+
60+
return { userInfo }
61+
}
62+
},
63+
profile(profile) {
64+
65+
const { userInfo } = profile
66+
67+
return {
68+
id: userInfo.user_id,
69+
name: userInfo.user,
70+
email: userInfo.user,
71+
72+
// TODO: get image from profile once it's available
73+
// Details available https://community.hubspot.com/t5/APIs-Integrations/Profile-photo-is-not-retrieved-with-User-API/m-p/325521
74+
image: null
75+
}
76+
},
77+
options,
78+
}
79+
}

1 commit comments

Comments
 (1)
Please sign in to comment.