Complete preliminary addition of infisical-node to support service tokens

This commit is contained in:
Tuan Dang
2023-03-14 16:38:30 +07:00
parent 1e859c19f4
commit 7fd06e36bc
47 changed files with 691 additions and 691 deletions
+8 -13
View File
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import * as Sentry from '@sentry/node';
import infisical from 'infisical-node';
import { Request, Response } from 'express';
import jwt from 'jsonwebtoken';
import * as Sentry from '@sentry/node';
import * as bigintConversion from 'bigint-conversion';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const jsrp = require('jsrp');
import { User, LoginSRPDetail } from '../../models';
import { createToken, issueAuthTokens, clearTokens } from '../../helpers/auth';
@@ -11,12 +12,6 @@ import {
ACTION_LOGIN,
ACTION_LOGOUT
} from '../../variables';
import {
NODE_ENV,
JWT_AUTH_LIFETIME,
JWT_AUTH_SECRET,
JWT_REFRESH_SECRET
} from '../../config';
import { BadRequestError } from '../../utils/errors';
import { EELogService } from '../../ee/services';
import { getChannelFromUserAgent } from '../../utils/posthog'; // TODO: move this
@@ -126,7 +121,7 @@ export const login2 = async (req: Request, res: Response) => {
httpOnly: true,
path: '/',
sameSite: 'strict',
secure: NODE_ENV === 'production' ? true : false
secure: infisical.get('NODE_ENV')! === 'production' ? true : false
});
const loginAction = await EELogService.createAction({
@@ -182,7 +177,7 @@ export const logout = async (req: Request, res: Response) => {
httpOnly: true,
path: '/',
sameSite: 'strict',
secure: NODE_ENV === 'production' ? true : false
secure: infisical.get('NODE_ENV') === 'production' ? true : false
});
const logoutAction = await EELogService.createAction({
@@ -237,7 +232,7 @@ export const getNewToken = async (req: Request, res: Response) => {
}
const decodedToken = <jwt.UserIDJwtPayload>(
jwt.verify(refreshToken, JWT_REFRESH_SECRET)
jwt.verify(refreshToken, infisical.get('JWT_REFRESH_SECRET')!)
);
const user = await User.findOne({
@@ -252,8 +247,8 @@ export const getNewToken = async (req: Request, res: Response) => {
payload: {
userId: decodedToken.userId
},
expiresIn: JWT_AUTH_LIFETIME,
secret: JWT_AUTH_SECRET
expiresIn: infisical.get('JWT_AUTH_LIFETIME')!,
secret: infisical.get('JWT_AUTH_SECRET')!
});
return res.status(200).send({