mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-22 12:49:09 +00:00
Saving oauth connections
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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(req, type): string {
|
||||
const plugin: string = req.route.path
|
||||
.replace('/oauth/', '')
|
||||
.replace('/callback', '');
|
||||
|
||||
const { query } = req;
|
||||
const {
|
||||
name,
|
||||
description,
|
||||
connector_id,
|
||||
connector_name,
|
||||
image_url,
|
||||
user_id,
|
||||
customer_id,
|
||||
customer_name,
|
||||
} = 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,
|
||||
};
|
||||
return jwt.sign({ ...newConnection }, process.env.JWT_PRIVATE_KEY);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user