Skip to content

Commit

Permalink
feat: add token
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Jun 21, 2022
1 parent 8050237 commit 3e13717
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ws/model/interface/index.ts
Expand Up @@ -11,6 +11,10 @@ export interface options {
* @default true
*/
authentication?: boolean;
/**
* @default 'null'
*/
token?: string
session?: string | string[] | undefined;
}

Expand Down
8 changes: 8 additions & 0 deletions src/ws/routers/functions/start-session.ts
Expand Up @@ -4,11 +4,13 @@ import { sessionClient } from '../../help/sessions';
import { spawn } from 'child_process';
import { InicializeRouters } from './inicialize-routers';
import { Request, Response } from 'express';
import crypto from 'crypto';

export async function startSession(req: Request, res: Response, option: options) {
const body = req.body;
const reHttp = /^https?:/;
const $_HEADERS_USER = req.headers.user;
const $_HEADERS_PASS = req.headers.user_pass;

if (option.authentication) {
const user = await Users.CheckUserLogin(req);
Expand All @@ -24,8 +26,14 @@ export async function startSession(req: Request, res: Response, option: options)
const session = await sessionClient.newSession($_HEADERS_USER);

if (session) {
const MergeToken = typeof $_HEADERS_USER === 'string' && typeof $_HEADERS_PASS === 'string'? $_HEADERS_USER + $_HEADERS_PASS: '';
const token = crypto
.createHash('md5')
.update(MergeToken)
.digest('hex');
option.session = $_HEADERS_USER;
option.url = body.url;
option.token = token;

const spawnArgs = [
__dirname + '../../../services/hydra.js',
Expand Down
1 change: 1 addition & 0 deletions src/ws/services/hydra.ts
Expand Up @@ -13,6 +13,7 @@ function sendParent(data: any) {
async function Webhook(options: any, info: any) {
if (!!options.url && options.url.length) {
return new Promise(async (resolve, reject) => {
Object.assign(info, {token: options.token})
await axios
.post(options.url, info)
.then(function (response) {
Expand Down

0 comments on commit 3e13717

Please sign in to comment.