import { Request, Response, NextFunction } from 'express'; import { Role, IDecoded, GatemanOptions, CreateSessionOptions, CreateHeadlessTokenOptions } from './typings'; export declare class Gateman { options: GatemanOptions; /** * Sets the redis object for persisting tokens, the secret key for sealing & unsealing * objects and the default session duration. * @param options Gateman config options */ constructor(options: GatemanOptions); /** * Persists a token using the user's id in Redis for a specific period of time * @param id The user's id * @param token The user's token * @param sessionDuration How long the token should be peristed to Redis in seconds. */ private persistSession; /** * Deletes a token from Redis using the user's id * @param id The user's id */ clearSession(id: string): Promise; /** * Creates an encrypted token using the user's id and role, and persists it to Redis for a specific period of time. * Used for creating `admin` and `user` sessions. Creates a `user` session token by default * @param options Options for creating the session */ createSession(options: CreateSessionOptions): Promise; /** * Creates a token that can be used for headless (i.e not triggered by a human user) inter-service calls by encrypting * the service name and the id of the user whom the call is made for. * The token is not persisted instead a TTL of 1 minute is attached to the token after which the token becomes invalidated. * @param options Options for creating the headless token */ createHeadlessToken(options: CreateHeadlessTokenOptions): Promise; /** * Decrypts an encrypted token and returns the data contained within * @param token Encrypted token */ decrypt(token: string): Promise; /** * Returns an Express middleware that guards requests to a particular endpoint using the token in the `Authorization` header against recognized `roles`. * @param roles The role(s) allowed to call the endpoint, defaults to `user`. Should be either `user` or `admin` * @param service The optional service(s) allowed to call the endpoint. `roles` should either contain or be `service` when this argument is provided. * If `service` is `"*"` all services can call the endpoint */ guard(roles?: Role | Role[], service?: string | string[]): (req: Request, res: Response, next: NextFunction) => Promise; }