mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 19:16:22 +00:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { Request, Response, NextFunction } from 'express';
|
|
import { Types } from 'mongoose';
|
|
import { ServiceAccount } from '../models';
|
|
import {
|
|
ServiceAccountNotFoundError
|
|
} from '../utils/errors';
|
|
import {
|
|
validateMembershipOrg
|
|
} from '../helpers/membershipOrg';
|
|
import {
|
|
validateClientForServiceAccount
|
|
} from '../helpers/serviceAccount';
|
|
|
|
type req = 'params' | 'body' | 'query';
|
|
|
|
const requireServiceAccountAuth = ({
|
|
acceptedRoles,
|
|
acceptedStatuses,
|
|
locationServiceAccountId = 'params',
|
|
requiredPermissions = []
|
|
}: {
|
|
acceptedRoles: string[];
|
|
acceptedStatuses: string[];
|
|
locationServiceAccountId?: req;
|
|
requiredPermissions?: string[];
|
|
}) => {
|
|
return async (req: Request, res: Response, next: NextFunction) => {
|
|
const serviceAccountId = req[locationServiceAccountId].serviceAccountId;
|
|
|
|
req.serviceAccount = await validateClientForServiceAccount({
|
|
authData: req.authData,
|
|
serviceAccountId: new Types.ObjectId(serviceAccountId),
|
|
requiredPermissions
|
|
});
|
|
|
|
next();
|
|
}
|
|
}
|
|
|
|
export default requireServiceAccountAuth; |