type Context = object; type NextFunction = (e: any) => Promise; type ExpressMiddlewareHandler = (request: object, response: object, next: NextFunction) => Promise; type RabbitMQMiddlewareHandler = (context: Context, message: object) => Promise; type ClaimOptions = { applicationToken: string, internalToken: any, decodedUser: any, cacheManager: any }; type CheckClaimOptions = { applicationToken: string, cacheManager: any }; type CSPKeys = 'companyCode' | 'state' | 'product'; type CSPFilter = { [key: CSPKeys]: any }; type MongoCspFilter = { $or: CSPFilter[][] } type MongoConditionFilter = { [key: string]: { $in: any[] } }; type ExpressJwtOptions = { /** Overrides the AUTH0_AUDIENCE environment variable. A comma delimited string or an array. */ audience?: string | string[] }; export type ServiceResourceRights = 'READ' | 'UPDATE' | 'INSERT'; export interface ServiceResource { code: string, service: string, name: string, uri: string, allowedRights: ServiceResourceRights[] } export interface UserServiceResource extends ServiceResource { mongoFilter: { $and: MongoConditionFilter | MongoCspFilter } }; type ResourceValidator = { getValidUserResourceList: (user: object, serviceResource: ServiceResource) => UserServiceResource[] }; function checkClaim(context: Context, accessKey: string, options: ClaimOptions): Promise function checkClaimMiddleware(options: CheckClaimOptions): { express: ExpressMiddlewareHandler, mq: RabbitMQMiddlewareHandler } function contextUserMiddleware(context: Context, options: ClaimOptions): Promise function redbirdJwtMiddleware(context: Context, request: object, response: object, next: NextFunction): Promise function setupUserSecurityResourceRpcMiddleware(serviceResource: ServiceResource[]): RabbitMQMiddlewareHandler function createSystemToken(context: Context): Promise; /** * @description (Middleware) Express middleware that populates a resource list that belongs to a user based on * the security resources from the service */ function setupUserSecurityResourceMiddleware(serviceResource: ServiceResource[]): ExpressMiddlewareHandler; /** * @description (Middleware) Exframe Context that populates a resource list that belongs to a user based on * the security resources from the service */ function setupContextUserSecurityResourceMiddleware(serviceResource: ServiceResource[]): (context: Context) => Promise; /** * @description (Middleware) express middleware that validates that a user has access to a given resource right pair * @param {string} resourceUri the resource to validate * @param {string} right the right against the resource to validate * @returns {function} middleware that will process the request */ function checkResourceAccessMiddleware(resourceUri: string, right: string): ExpressMiddlewareHandler; /** * @description (Middleware) Express middleware that gets the user profile from Falcon using the access key * based on the access key that is passed from the request. */ const falconSecurityMiddleware: ExpressMiddlewareHandler; const falconSecurityRpcMiddleware: RabbitMQMiddlewareHandler; /** * @description (Middleware) Express middleware that validates the RS256 JWT token on the request and * populates `req.user`. Can be used directly as middleware, or called with options to override the * AUTH0_AUDIENCE environment variable (e.g. `expressJwtMiddleware({ audience: 'my-audience' })`). */ interface ExpressJwtMiddleware { (request: object, response: object, next: NextFunction): Promise; (options?: ExpressJwtOptions): ExpressMiddlewareHandler; } const expressJwtMiddleware: ExpressJwtMiddleware; const resourceValidator: ResourceValidator; interface JwksClient { constructor(options: any); getJwks(): Promise; getSigningKeys(): any[]; getSigningKey(kid: string): Promise; } export class JwksClient implements JwksClient {}; const ExframeSecurity = { checkClaim, checkClaimMiddleware, checkResourceAccessMiddleware, contextUserMiddleware, createSystemToken, expressJwtMiddleware, falconSecurityMiddleware, falconSecurityRpcMiddleware, JwksClient, resourceValidator, redbirdJwtMiddleware, setupUserSecurityResourceMiddleware, setupUserSecurityResourceRpcMiddleware, setupContextUserSecurityResourceMiddleware }; export default ExframeSecurity;