UNPKG

@re-auth/http-adapters

Version:

HTTP protocol adapters for ReAuth - framework-agnostic integration with Express, Fastify, and Hono

92 lines (89 loc) 2.95 kB
import { LoggerInterface } from '@re-auth/logger'; import { HttpAdapterConfig, PluginEndpoint, AuthStepRequest, AuthStepResponse, SessionRequest, SessionResponse, ApiResponse, PluginListResponse, HttpRequest, AuthenticatedUser, FrameworkAdapter, RouteHandler, HttpResponse } from './types.cjs'; import '@re-auth/reauth'; import '@re-auth/reauth/services'; import 'hono/utils/cookie'; declare class ReAuthHttpAdapter { private engine; protected config: HttpAdapterConfig; private endpoints; private logger; constructor(config: HttpAdapterConfig, logger: LoggerInterface); /** * Get adapter configuration */ getConfig(): HttpAdapterConfig; /** * Build endpoint map from registered plugins */ private buildEndpoints; /** * Get all available endpoints */ getEndpoints(): PluginEndpoint[]; /** * Get endpoint by plugin and step name */ getEndpoint(pluginName: string, stepName: string): PluginEndpoint | undefined; /** * Execute authentication step */ executeAuthStep(req: AuthStepRequest, deviceInfo: Record<string, any>): Promise<AuthStepResponse>; /** * Create a new session */ createSession(req: SessionRequest, deviceInfo: Record<string, any>): Promise<SessionResponse>; /** * Check session validity */ checkSession(req: SessionRequest, deviceInfo: Record<string, any>): Promise<SessionResponse>; /** * Destroy current session */ destroySession(req: SessionRequest): Promise<ApiResponse>; /** * List all available plugins */ listPlugins(): Promise<PluginListResponse>; /** * Get specific plugin details */ getPlugin(pluginName: string): Promise<ApiResponse>; /** * Get full introspection data */ getIntrospection(): Promise<ApiResponse>; /** * Health check endpoint */ healthCheck(): Promise<ApiResponse>; /** * Extract session token from request */ private extractSessionToken; /** * Extract step input from request */ private extractStepInput; /** * Get current authenticated user from request */ getCurrentUser(req: HttpRequest, deviceInfo: Record<string, any>): Promise<AuthenticatedUser | null>; /** * Authenticate request and return user or throw error */ requireAuthentication(req: HttpRequest, deviceInfo: Record<string, any>): Promise<AuthenticatedUser>; /** * Create framework-specific adapter */ createAdapter<TRequest = any, TResponse = any, TNext = any>(adapter: FrameworkAdapter<TRequest, TResponse, TNext>): FrameworkAdapter<TRequest, TResponse, TNext>; /** * Generic route handler factory */ createRouteHandler(handler: RouteHandler): (req: HttpRequest, res: HttpResponse) => Promise<void>; /** * Error handler */ private handleError; } export { ReAuthHttpAdapter };