hubspot guard

This commit is contained in:
Gabriel Rosa
2022-06-20 17:09:28 -03:00
parent 8c91551cdc
commit 072a9fee8e
4 changed files with 25 additions and 10 deletions
+2
View File
@@ -31,6 +31,7 @@ import { InputsClientConfiguration } from './clients/inputs/client.config';
import { PipelinesClientConfiguration } from './clients/pipelines/client.config';
import { CatalogController } from './modules/catalog/catalog.controller';
import { CatalogService } from './modules/catalog/catalog.service';
import { HubspotStrategy } from './modules/inputs/passport-strategies/hubspot';
const authClient = new AuthClient();
const inputClient = new InputsClientConfiguration();
@@ -61,6 +62,7 @@ const transformationClient = new TransformationsClientConfiguration();
PipelinesClientService,
AuthClientService,
CatalogService,
HubspotStrategy,
],
imports: [
ConfigModule.forRoot({
+13
View File
@@ -6,6 +6,8 @@ import {
Param,
Patch,
Post,
Req,
UseGuards,
} from '@nestjs/common';
import { InputsService } from './inputs.service';
import { InputsClientService } from 'src/clients/inputs/client.service';
@@ -21,6 +23,7 @@ import {
TestConnectionReq,
TestConnectionRes,
} from './dtos/input.model';
import { AuthGuard } from '@nestjs/passport';
@ApiTags('inputs')
@Controller('inputs')
@@ -125,4 +128,14 @@ 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 +1,18 @@
import { Strategy } from 'passport-hubspot';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
@Injectable()
export class HubspotStrategy extends PassportStrategy(Strategy) {
constructor(private authService: AuthService) {
super();
constructor() {
super({
clientID: 'asd',
clientSecret: '',
callbackURL: 'http://localhost:4200/coletix/auth-callback',
});
}
async validate(username: string, password: string): Promise<any> {
const user = await this.authService.validateUser(username, password);
if (!user) {
throw new UnauthorizedException();
}
return user;
async validate(accessToken: string, refreshToken: string) {
return { accessToken, refreshToken };
}
}
+1 -1
View File
File diff suppressed because one or more lines are too long