mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-24 18:09:09 +00:00
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ConnectionDto } from '../connection/dtos/connection';
|
|
import jwt from 'jsonwebtoken';
|
|
import { PartialType } from '@nestjs/swagger';
|
|
|
|
class PartialConnection extends PartialType(ConnectionDto) {}
|
|
|
|
@Injectable()
|
|
export class OauthService {
|
|
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 {
|
|
name,
|
|
description,
|
|
connector_id,
|
|
connector_name,
|
|
image_url,
|
|
user_id,
|
|
customer_id,
|
|
customer_name,
|
|
id,
|
|
} = query;
|
|
|
|
const properties = { plugin, credentials_type: 'oauth' };
|
|
for (const key in query) {
|
|
if (key.includes('properties.')) {
|
|
const propertyKey = key.split('.')[1];
|
|
properties[propertyKey] = query[key];
|
|
}
|
|
}
|
|
|
|
const newConnection: PartialConnection = {
|
|
name,
|
|
description,
|
|
connector_id,
|
|
connector_name,
|
|
image_url,
|
|
user_id,
|
|
customer_id,
|
|
customer_name,
|
|
type,
|
|
properties,
|
|
plugin,
|
|
id,
|
|
};
|
|
return jwt.sign({ ...newConnection }, process.env.JWT_PRIVATE_KEY);
|
|
}
|
|
}
|