1.0.0-alpha.10 • Published 5 months ago
@re-auth/http-adapters v1.0.0-alpha.10
@reauth/http-adapters
HTTP adapters for ReAuth authentication framework. This package provides HTTP server adapters to easily integrate ReAuth with various Node.js HTTP frameworks.
Features
- Auto-Introspection: Automatically discovers all ReAuth plugins and creates HTTP routes for their steps
- Framework Support: Express.js, Fastify, and Hono adapters
- Route Overriding: Override any auto-generated plugin route with custom logic
- Custom Routes: Add additional routes for external plugins or custom functionality
- Flexible Configuration: Global middleware, custom error handlers, and more
- TypeScript Support: Full type safety with comprehensive interfaces
Installation
pnpm add @reauth/http-adapters @reauth/reauthAvailable Adapters
Usage
Express
import express from 'express';
import { createExpressAdapter } from '@reauth/http-adapters/express';
import { reauth } from '@reauth/reauth';
const app = express();
const auth = reauth({
// Your ReAuth configuration
});
app.use(express.json());
app.use(createExpressAdapter(auth));
app.listen(3000, () => {
console.log('Server running on http://localhost:3000');
});Fastify
import Fastify from 'fastify';
import { createFastifyAdapter } from '@reauth/http-adapters/fastify';
import { reauth } from '@reauth/reauth';
const app = Fastify();
const auth = reauth({
// Your ReAuth configuration
});
app.register(createFastifyAdapter(auth));
app.listen({ port: 3000 }, (err) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log('Server running on http://localhost:3000');
});API Reference
createExpressAdapter(auth: ReAuth, options?: ExpressAdapterOptions)
Creates an Express middleware function that handles ReAuth HTTP requests.
createFastifyAdapter(auth: ReAuth, options?: FastifyAdapterOptions)
Creates a Fastify plugin that handles ReAuth HTTP requests.
Development
- Clone the repository
- Install dependencies:
pnpm install - Start development server:
pnpm dev
License
MIT
Sequence Diagram
sequenceDiagram
participant User
participant HonoAdapter
participant HttpAdapterFactory
participant HonoFrameworkAdapter
participant ReAuthEngine
User->>HonoAdapter: createHonoAdapter(engine, config)
note right of User: config contains contextRules
HonoAdapter->>HttpAdapterFactory: createHttpAdapter(frameworkAdapter)
HttpAdapterFactory->>HonoFrameworkAdapter: setupMiddleware(context)
User->>HonoApp: Request to /auth/{pluginName}/{stepName}
HonoApp->>HonoFrameworkAdapter: auto-generated step handler
HonoFrameworkAdapter->>HonoFrameworkAdapter: extractInputs(context, pluginName, stepName)
HonoFrameworkAdapter->>HonoFrameworkAdapter: addConfigurableContextInputs(context, inputs, pluginName, stepName, contextRules)
HonoFrameworkAdapter->>HttpAdapterFactory: findContextRules(pluginName, stepName, contextRules)
HttpAdapterFactory-->>HonoFrameworkAdapter: applicableRules
HonoFrameworkAdapter->>HonoFrameworkAdapter: Extract cookies/headers from request based on rules
HonoFrameworkAdapter->>ReAuthEngine: engine.executeStep(pluginName, stepName, inputs)
ReAuthEngine-->>HonoFrameworkAdapter: result: AuthOutput
HonoFrameworkAdapter->>HonoFrameworkAdapter: handleConfigurableContextOutputs(context, response, result, pluginName, stepName, contextRules)
HonoFrameworkAdapter->>HttpAdapterFactory: findContextRules(pluginName, stepName, contextRules)
HttpAdapterFactory-->>HonoFrameworkAdapter: applicableRules
HonoFrameworkAdapter->>HonoFrameworkAdapter: Set cookies/headers on response based on rules
HonoFrameworkAdapter->>HonoApp: handleStepResponse(context, response, result, httpConfig)
HonoApp-->>User: Response with data and cookies/headers1.0.0-alpha.10
5 months ago
1.0.0-alpha.9
5 months ago
1.0.0-alpha.8
5 months ago
1.0.0-alpha.7
5 months ago
1.0.0-alpha.6
5 months ago
1.0.0-alpha.5
5 months ago
1.0.0-alpha.4
5 months ago
1.0.0-alpha.3
5 months ago
1.0.0-alpha.2
5 months ago
0.1.0-alpha.1
5 months ago