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
-13
View File
@@ -6,8 +6,6 @@ import {
Param,
Patch,
Post,
Req,
UseGuards,
} from '@nestjs/common';
import { InputsService } from './inputs.service';
import { InputsClientService } from 'src/clients/inputs/client.service';
@@ -23,7 +21,6 @@ import {
TestConnectionReq,
TestConnectionRes,
} from './dtos/input.model';
import { AuthGuard } from '@nestjs/passport';
@ApiTags('inputs')
@Controller('inputs')
@@ -128,14 +125,4 @@ export class InputsController {
return response;
}
@UseGuards(AuthGuard('hubspot'))
@Get('oauth/hubspot')
async oauthHubspot(@Req() req) {
return true;
}
@Get('oauth/hubspot/callback')
async oauthHubspotCallback(@Req() req) {
return true;
}
}
@@ -1,18 +0,0 @@
import { Strategy } from 'passport-hubspot';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
@Injectable()
export class HubspotStrategy extends PassportStrategy(Strategy) {
constructor() {
super({
clientID: 'asd',
clientSecret: '',
callbackURL: 'http://localhost:4200/coletix/auth-callback',
});
}
async validate(accessToken: string, refreshToken: string) {
return { accessToken, refreshToken };
}
}
+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);
}
}