UNPKG

@citrineos/util

Version:

The OCPP util module which supplies helpful utilities like cache and queue connectors, etc.

53 lines (52 loc) 1.46 kB
import type { FastifyPluginAsync, FastifyReply } from 'fastify'; import type { ILogObj } from 'tslog'; import { Logger } from 'tslog'; import type { IApiAuthProvider, UserInfo } from '@citrineos/base'; /** * Options for the authentication plugin */ export interface AuthPluginOptions { /** * Routes that don't require authentication */ excludedRoutes?: string[]; /** * Enable verbose debug logging */ debug?: boolean; } /** * Extend the FastifyRequest interface to include user information */ declare module 'fastify' { interface FastifyRequest { /** * Authenticated user information */ user?: UserInfo; } } /** * Extend FastifyInstance to include our auth functions and provider */ declare module 'fastify' { interface FastifyInstance { /** * The authentication provider instance */ authProvider: IApiAuthProvider; /** * Authenticates a request by validating the token in Authorization header */ authenticate: (request: FastifyRequest, reply: FastifyReply) => Promise<void>; /** * Authorizes a request for a specific resource */ authorize: (request: FastifyRequest, reply: FastifyReply) => Promise<void>; } } export declare const apiAuthPluginFp: FastifyPluginAsync<{ provider: IApiAuthProvider; options?: AuthPluginOptions; logger?: Logger<ILogObj>; }>;