mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-09 07:29:07 +00:00
Merge branch 'ft/connection-manager' of https://github.com/dadosfera/maestro into ft/connection-manager
This commit is contained in:
@@ -4,6 +4,7 @@ import { AuthGuard } from '@nestjs/passport';
|
||||
import { ConnectionClientService } from '../connection/client.service';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import DadosferaLogger from '@dadosfera/dadosfera-logs/dist';
|
||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||
@ApiTags('oauth')
|
||||
@Controller('oauth')
|
||||
export class OauthController {
|
||||
@@ -157,7 +158,7 @@ export class OauthController {
|
||||
try {
|
||||
const response = await this.connectionService.createConnection(
|
||||
connectionInfo,
|
||||
{ customer_id, customer_name, user_id },
|
||||
PackTheMetadata({ customer_id, customer_name, user_id }),
|
||||
);
|
||||
this.redirectUrl.searchParams.set(
|
||||
'connection_id',
|
||||
|
||||
@@ -7,10 +7,11 @@ class PartialConnection extends PartialType(ConnectionDto) {}
|
||||
|
||||
@Injectable()
|
||||
export class OauthService {
|
||||
generateStateFromRequest(req, type): string {
|
||||
const plugin: string = req.route.path
|
||||
.replace('/oauth/', '')
|
||||
.replace('/callback', '');
|
||||
generateStateFromRequest(prevState, req, type): string {
|
||||
if (req.route.path.includes('callback')) {
|
||||
return prevState;
|
||||
}
|
||||
const plugin: string = req.route.path.replace('/oauth/', '');
|
||||
|
||||
const { query } = req;
|
||||
const {
|
||||
@@ -43,6 +44,7 @@ export class OauthService {
|
||||
customer_name,
|
||||
type,
|
||||
properties,
|
||||
plugin,
|
||||
};
|
||||
return jwt.sign({ ...newConnection }, process.env.JWT_PRIVATE_KEY);
|
||||
}
|
||||
|
||||
@@ -10,12 +10,14 @@ import { OauthSecrets } from 'src/utils/OauthSecrets';
|
||||
import { Request } from 'express';
|
||||
import { ParamsDictionary } from 'express-serve-static-core';
|
||||
import { ParsedQs } from 'qs';
|
||||
import { OauthService } from '../oauth.service';
|
||||
|
||||
@Injectable()
|
||||
export class FacebookStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(
|
||||
@Inject('OAUTH_SECRETS')
|
||||
private readonly oauthSecrets: OauthSecrets,
|
||||
private oauthService: OauthService,
|
||||
) {
|
||||
const options: StrategyOption = {
|
||||
clientID: oauthSecrets.facebook.client_id,
|
||||
@@ -37,8 +39,11 @@ export class FacebookStrategy extends PassportStrategy(Strategy) {
|
||||
req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>,
|
||||
options?: any,
|
||||
): void {
|
||||
const { customer_id } = req.query;
|
||||
options.state = customer_id;
|
||||
options.state = this.oauthService.generateStateFromRequest(
|
||||
options.state,
|
||||
req,
|
||||
'application',
|
||||
);
|
||||
options.scope = 'ads_read ads_management';
|
||||
super.authenticate(req, options);
|
||||
}
|
||||
|
||||
@@ -52,13 +52,18 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
||||
switch (plugin) {
|
||||
case 'googleads':
|
||||
options.state = this.oauthService.generateStateFromRequest(
|
||||
options.state,
|
||||
req,
|
||||
'application',
|
||||
);
|
||||
options.scope.push('https://www.googleapis.com/auth/adwords');
|
||||
break;
|
||||
case 'google-sheets':
|
||||
options.state = this.oauthService.generateStateFromRequest(req, 'file');
|
||||
options.state = this.oauthService.generateStateFromRequest(
|
||||
options.state,
|
||||
req,
|
||||
'file',
|
||||
);
|
||||
options.scope.push(
|
||||
'https://www.googleapis.com/auth/drive.metadata.readonly',
|
||||
'https://www.googleapis.com/auth/spreadsheets.readonly',
|
||||
|
||||
@@ -28,6 +28,7 @@ export class HubspotStrategy extends PassportStrategy(Strategy) {
|
||||
|
||||
authenticate(req, options) {
|
||||
options.state = this.oauthService.generateStateFromRequest(
|
||||
options.state,
|
||||
req,
|
||||
'application',
|
||||
);
|
||||
|
||||
@@ -30,10 +30,12 @@ export class MailChimpStrategy extends PassportStrategy(Strategy, 'mailchimp') {
|
||||
}
|
||||
|
||||
authenticate(@Req() req, options) {
|
||||
options.state = this.oauthService.generateStateFromRequest(
|
||||
req,
|
||||
'application',
|
||||
);
|
||||
if (!req.route.path.includes('callback'))
|
||||
options.state = this.oauthService.generateStateFromRequest(
|
||||
options.state,
|
||||
req,
|
||||
'application',
|
||||
);
|
||||
super.authenticate(req, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,11 @@ export class SalesforceStrategy extends PassportStrategy(
|
||||
}
|
||||
|
||||
authenticate(req, options) {
|
||||
options.state = this.oauthService.generateStateFromRequest(req, 'file');
|
||||
options.state = this.oauthService.generateStateFromRequest(
|
||||
options.state,
|
||||
req,
|
||||
'file',
|
||||
);
|
||||
super.authenticate(req, options);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user