mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-14 10:29:08 +00:00
get credentials from AWS secrets manager
This commit is contained in:
@@ -1,20 +1,54 @@
|
||||
import { Controller, Get, Req, UseGuards } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
Controller,
|
||||
Get,
|
||||
Query,
|
||||
Redirect,
|
||||
Req,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { InputsClientService } from 'src/clients/inputs/client.service';
|
||||
import { InputsService } from '../inputs/inputs.service';
|
||||
|
||||
@ApiTags('oauth')
|
||||
@Controller('oauth')
|
||||
export class OauthController {
|
||||
inputService: InputsService;
|
||||
frontendRedirectUri = '';
|
||||
constructor(private inputsClientService: InputsClientService) {
|
||||
this.inputService = new InputsService(this.inputsClientService);
|
||||
switch (process.env.ENV) {
|
||||
case 'dev':
|
||||
case 'stg':
|
||||
this.frontendRedirectUri = `https://app.${process.env.ENV}.dadosfera.ai/auth-callback`;
|
||||
break;
|
||||
case 'prd':
|
||||
this.frontendRedirectUri = `https://app.dadosfera.ai/auth-callback`;
|
||||
break;
|
||||
default:
|
||||
this.frontendRedirectUri = `http://localhost:4200/coletix/auth-callback`;
|
||||
}
|
||||
}
|
||||
@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');
|
||||
@Redirect()
|
||||
async oauthHubspotCallback(@Req() req, @Query('state') customer_id) {
|
||||
const { authInfo } = req;
|
||||
if (!authInfo) throw new BadRequestException('Oauth tokens not found');
|
||||
const { accessToken, refreshToken } = authInfo;
|
||||
const response = await this.inputService.create({
|
||||
info: { customer_id, customer: 'customer', user_id: 'empty' },
|
||||
plugin: 'hubspot',
|
||||
credentials: { access_token: accessToken, refresh_token: refreshToken },
|
||||
});
|
||||
return { url: `${this.frontendRedirectUri}?input_id=${response.input.id}` };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user