hubspot oauth

This commit is contained in:
Gabriel Rosa
2022-06-22 15:24:36 -03:00
parent 072a9fee8e
commit da3b7f3096
8 changed files with 136 additions and 33 deletions
+20
View File
@@ -0,0 +1,20 @@
import { Controller, Get, Req, UseGuards } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
@ApiTags('oauth')
@Controller('oauth')
export class OauthController {
@UseGuards(AuthGuard('hubspot'))
@Get('hubspot')
async oauthHubspot(@Req() req) {
console.log(req);
return true;
}
@UseGuards(AuthGuard('hubspot'))
@Get('hubspot/callback')
async oauthHubspotCallback() {
console.log('hubspot/callback');
}
}
@@ -0,0 +1,28 @@
import { Strategy } from 'passport-hubspot-oauth2';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
@Injectable()
export class HubspotStrategy extends PassportStrategy(Strategy) {
constructor() {
super(
{
clientID: 'c51bc9c9-e81c-4263-887e-7cc68ab8e185',
clientSecret: '99a8bb9d-b622-4ea7-a46c-77b74f98ce80',
callbackURL: 'http://localhost:3333/oauth/hubspot/callback',
redirectUri: 'http://localhost:3333/oauth/hubspot/callback',
scope:
'automation business-intelligence oauth forms integration-sync sales-email-read crm.lists.read crm.objects.contacts.read crm.schemas.contacts.read crm.objects.companies.read crm.objects.deals.read crm.schemas.companies.read crm.schemas.deals.read crm.objects.owners.read crm.objects.quotes.read crm.schemas.quotes.read crm.objects.line_items.read crm.schemas.line_items.read',
passReqToCallback: true,
},
(accessToken, refreshToken, tokenInfo, profile, done) => {
return done(null, profile, { accessToken, refreshToken, tokenInfo });
},
);
}
authenticate(req, options) {
options.state = 'customer_id';
super.authenticate(req, options);
}
}