UNPKG

local-tokens

Version:

Bundled oauth-mock-server with pre-configured token clients (sinple-oauth2) for testing services and middleware

61 lines 1.95 kB
import type { Request as ExpressRequest } from 'express'; /** * Payload values that can be used in token hooks */ interface AcceptedPayloadValues { [x: string]: string | boolean | string[] | boolean[]; } export type Hook<Options = any | string> = (options?: Options) => HookFunction; export type HookFunction<TPayload = AcceptedPayloadValues> = (token: { payload: TPayload; }, req: ExpressRequest) => void; /** * oauth-server-hooks supported atm */ interface HookTypes { /** * This allows middleware to modify tokens BEFORE they are signed */ beforeTokenSigning: Map<string, HookFunction>; } /** * Manage hooks for LocalTokenServer */ export declare class LocalTokenHooks { private _hooks; constructor(); /** * Get all registered hook names * * @returns {array<string>} Array of hook names */ get registered(): "beforeTokenSigning"[]; /** * Add a hook by name * - should match oauth-mock-server hook name * - See `./hooks` for examples * * @param hookName {string} Name of the hook to add (example: beforeTokenSigning) * @param fn {function} Hook function to be executed on hookName */ add(hookName: keyof HookTypes, fn: HookFunction): string; /** * Remove a hook by name and function * - should match oauth-mock-server hook name * * @param hookName {string} Name of the hook to remove * @param hook {function} Hook function to remove */ remove(hookName: keyof HookTypes, hook: string): boolean; /** * Execute all hooks for a given hookName * - should match oauth-mock-server hook name * - example: beforeTokenSigning * * @param hookName {string} Name of the hook to execute * @param args {array} arguments to pass into hook (example: [token, req]) */ execute(hookName: keyof HookTypes, args: any): Promise<void>; } export {}; //# sourceMappingURL=hooks.d.ts.map