mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-16 00:39:08 +00:00
update libs
This commit is contained in:
@@ -2,7 +2,6 @@ import {
|
||||
BadRequestException,
|
||||
Controller,
|
||||
Get,
|
||||
Query,
|
||||
Redirect,
|
||||
Req,
|
||||
UseGuards,
|
||||
@@ -11,6 +10,7 @@ import { ApiTags } from '@nestjs/swagger';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { InputsClientService } from 'src/clients/inputs/client.service';
|
||||
import { InputsService } from '../inputs/inputs.service';
|
||||
import { Request } from 'express';
|
||||
|
||||
@ApiTags('oauth')
|
||||
@Controller('oauth')
|
||||
@@ -40,15 +40,52 @@ export class OauthController {
|
||||
@Get('hubspot/callback')
|
||||
@UseGuards(AuthGuard('hubspot'))
|
||||
@Redirect()
|
||||
async oauthHubspotCallback(@Req() req, @Query('state') customer_id) {
|
||||
async oauthHubspotCallback(@Req() req) {
|
||||
return await this.callback(req, 'hubspot');
|
||||
}
|
||||
|
||||
@Get('google')
|
||||
@UseGuards(AuthGuard('google'))
|
||||
async oauthGoogle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Get('google/callback')
|
||||
@UseGuards(AuthGuard('google'))
|
||||
@Redirect()
|
||||
async oauthGoogleCallback(@Req() req) {
|
||||
return await this.callback(req, 'google');
|
||||
}
|
||||
|
||||
@Get('facebook')
|
||||
@UseGuards(AuthGuard('facebook'))
|
||||
async oauthFacebook() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Get('facebook/callback')
|
||||
@UseGuards(AuthGuard('facebook'))
|
||||
@Redirect()
|
||||
async oauthFacebookCallback(@Req() req) {
|
||||
return await this.callback(req, 'facebook');
|
||||
}
|
||||
|
||||
async callback(@Req() req, plugin) {
|
||||
const { authInfo } = req;
|
||||
|
||||
const request: Request = req;
|
||||
|
||||
if (!authInfo) throw new BadRequestException('Oauth tokens not found');
|
||||
const { accessToken, refreshToken } = authInfo;
|
||||
|
||||
const { accessToken: access_token, refreshToken: refresh_token } = authInfo;
|
||||
const { customer_id } = request.query;
|
||||
|
||||
const response = await this.inputService.create({
|
||||
info: { customer_id, customer: 'customer', user_id: 'empty' },
|
||||
plugin: 'hubspot',
|
||||
credentials: { access_token: accessToken, refresh_token: refreshToken },
|
||||
plugin,
|
||||
credentials: { access_token, refresh_token },
|
||||
});
|
||||
|
||||
return { url: `${this.frontendRedirectUri}?input_id=${response.input.id}` };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user