UNPKG

saget-auth-middleware

Version:

A comprehensive authentication middleware for Node.js applications with SSO integration, JWT validation, and role-based access control

94 lines (82 loc) 2.23 kB
/** * SAGET Auth Middleware TypeScript Definitions * A comprehensive authentication middleware for Node.js applications * * @version 2.1.1 * @author PIJAR TEKNOLOGI * @license MIT */ import { NextRequest, NextResponse } from 'next/server'; // Configuration interfaces export interface MiddlewareConfig { PUBLIC_PATHS?: string[]; ACCESS_CONTROL?: Record<string, string[]>; COOKIE_NAMES?: { ACCESS_TOKEN?: string; REFRESH_TOKEN?: string; APPLICATION_TOKEN?: string; }; SSO_LOGIN_URL?: string; } export interface SSOConfig { baseUrl: string; clientId: string; clientSecret: string; redirectUri: string; scope?: string; responseType?: string; grantType?: string; } export interface AuthConfig { sso?: SSOConfig; publicPaths?: string[]; tokenRefreshThreshold?: number; enableLogging?: boolean; rbac?: { enabled: boolean; roles: Record<string, string[]>; }; } // Token interfaces export interface DecodedToken { sub: string; iat: number; exp: number; role?: string; applications?: { role: string; [key: string]: any; }; [key: string]: any; } export interface TokenRefreshResponse { accessToken: string; refreshToken: string; applicationToken: string; } // Middleware function types export type MiddlewareFunction = (req: NextRequest) => Promise<NextResponse>; // Main exports export function configureMiddleware(config?: MiddlewareConfig): MiddlewareFunction; export const middleware: MiddlewareFunction; export const config: { matcher: string[]; }; // Default export declare const _default: MiddlewareFunction; export default _default; // Utility functions (if exposed) export interface AuthUtilities { decodeJwtToken(token: string): Promise<DecodedToken | null>; hasAuthCookies(req: NextRequest): Promise<boolean | null>; checkAuthorization(req: NextRequest): Promise<boolean>; } // CLI types export interface CLIConfig { framework: 'nextjs' | 'express'; language: 'javascript' | 'typescript'; output: string; } // Generator function types export function generateJSMiddleware(outputDir: string, config: CLIConfig): Promise<void>; export function generateTSMiddleware(outputDir: string, config: CLIConfig): Promise<void>;