@re-auth/http-adapters
Version:
HTTP adapters for ReAuth authentication framework
110 lines • 4.63 kB
TypeScript
import { type Context, Hono } from "hono";
import type { ReAuthEngine, AuthOutput, Entity, AuthToken } from "@re-auth/reauth";
import { type BaseHttpConfig, type FrameworkAdapter, type HttpAdapterContext, type RouteOverride, type CustomRoute, createRouteOverride, createCustomRoute, createAutoIntrospectionConfig, introspectReAuthEngine, type AutoGeneratedRoute, type AutoIntrospectionConfig, createContextRule, OAuth2ContextRules, type ContextExtractionRule } from "../../utils/http-adapter-factory";
/**
* Hono-specific configuration
*/
export interface HonoAdapterConfig extends BaseHttpConfig {
}
/**
* Hono framework adapter implementation
*/
declare class HonoFrameworkAdapter implements FrameworkAdapter<HonoAdapterConfig> {
private app;
private engine?;
private contextRules;
private adapterConfig;
constructor(engine?: ReAuthEngine, app?: Hono);
/**
* Set the ReAuth engine instance (for shared adapter pattern)
*/
setEngine(engine: ReAuthEngine): void;
/**
* Set context rules (for shared adapter pattern)
*/
setContextRules(rules: ContextExtractionRule[]): void;
/**
* Set adapter config (for shared adapter pattern)
*/
setAdapterConfig(config: any): void;
/**
* Get expected inputs for a plugin step
*/
private getExpectedInputs;
setupMiddleware(context: HttpAdapterContext): void;
createRoute(method: string, path: string, handler: any, middleware?: any[]): void;
extractInputs(context: Context, pluginName: string, stepName: string): Promise<Record<string, any>>;
/**
* Add configurable context inputs from cookies and headers based on context rules
*/
addConfigurableContextInputs(context: Context, inputs: Record<string, any>, pluginName: string, stepName: string, contextRules: ContextExtractionRule[]): void;
handleStepResponse(context: Context, response: any, // Not used in Hono, context handles response
result: AuthOutput, httpConfig: any): Response;
/**
* Handle configurable context outputs (set cookies and headers) based on context rules
*/
handleConfigurableContextOutputs(context: Context, response: any, // Not used in Hono
result: AuthOutput, pluginName: string, stepName: string, contextRules: ContextExtractionRule[]): void;
private getStatusCode;
extractToken(context: Context): string | null;
requireAuth(): any;
errorResponse(context: any, error: Error): Response;
getAdapter(): Hono;
}
/**
* Create Hono adapter using the factory pattern with shared instance
*/
export declare const createHonoAdapterV2: (engine: ReAuthEngine, config: HonoAdapterConfig, frameworkAdapter: HonoFrameworkAdapter) => any;
/**
* Hono adapter class with additional features
*/
export declare class HonoAdapterV2 {
private app;
private engine;
private config;
private frameworkAdapter;
constructor(engine: ReAuthEngine, config: HonoAdapterConfig | undefined, app: Hono, frameworkAdapter?: HonoFrameworkAdapter);
/**
* Get the Hono app
*/
getApp(): Hono;
getAdapter(): HonoFrameworkAdapter;
/**
* Add a custom route
*/
addRoute(method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH", path: string, handler: (c: Context) => Promise<Response> | Response, options?: {
middleware?: any[];
requireAuth?: boolean;
}): void;
/**
* Protection middleware for routes
*/
protect(options?: ProtectOptions): (c: Context, next: any) => Promise<(Response & import("hono").TypedResponse<{
error: string;
}, 401, "json">) | (Response & import("hono").TypedResponse<{
error: string;
}, 403, "json">) | (Response & import("hono").TypedResponse<{
error: string;
}, 500, "json">) | undefined>;
}
declare module "hono" {
interface ContextVariableMap {
entity?: Entity;
authenticated: boolean;
token: AuthToken;
}
}
/**
* Protection options
*/
interface ProtectOptions {
roles?: string[];
authorize?: (entity: Entity, context: Context) => Promise<boolean> | boolean;
}
/**
* Convenience function to create Hono adapter with options
*/
export declare function createHonoAdapter(engine: ReAuthEngine, config: HonoAdapterConfig | undefined, app: Hono): HonoAdapterV2;
export { createRouteOverride, createCustomRoute, createAutoIntrospectionConfig, introspectReAuthEngine, createContextRule, OAuth2ContextRules, HonoFrameworkAdapter, };
export type { RouteOverride, CustomRoute, AutoGeneratedRoute, AutoIntrospectionConfig, ContextExtractionRule, };
//# sourceMappingURL=hono-adapter-v2.d.ts.map