@kya-os/mcp-i
Version:
The TypeScript MCP framework with identity features built-in
44 lines (43 loc) • 1.25 kB
TypeScript
import { RequestHandler } from "express";
import { JwtPayload, VerifyOptions } from "jsonwebtoken";
declare global {
namespace Express {
interface Request {
user?: JwtPayload;
ctx?: {
agent?: {
did?: string;
kid?: string;
session?: string;
scopes?: string[];
delegationRef?: string;
confidence?: string;
verifiedAt?: number;
};
};
}
}
}
export interface JWTAuthMiddlewareConfig extends VerifyOptions {
secret: string;
}
/**
* Middleware to authenticate requests using a JWT.
* @param config - Configuration object containing the JWT secret and verify options.
* @returns Express middleware function.
*
* @example
* ```ts
* const middleware = jwtAuthMiddleware({
* secret: process.env.JWT_SECRET!,
* algorithms: ["HS256"],
* issuer: "https://example.com",
* audience: "https://example.com",
* subject: "user-id",
* expiresIn: "1h",
* notBefore: "1h",
* clockTolerance: 30,
* });
* ```
*/
export declare function jwtAuthMiddleware(config: JWTAuthMiddlewareConfig): RequestHandler;