UNPKG

elysia-oauth2-resource-server

Version:
61 lines (60 loc) 1.67 kB
import type { Elysia } from "elysia"; import { type JWTPayload } from "jose"; /** * Options for configuring the OAuth2 Resource Server */ export interface OAuth2ResourceServerOptions { /** URL to the JWKS endpoint (typically ends with /.well-known/jwks.json) */ jwksUri: string; /** Expected issuer value (must match the JWT's iss claim) */ issuer: string; /** Expected audience value(s) (must be included in the JWT's aud claim) */ audience?: string | string[]; /** List of scopes that must be present in the token */ requiredScopes?: string[]; /** Options for JWKS retrieval and caching */ jwksOptions?: { /** Max age of cached JWKS in milliseconds (default: 10 minutes) */ cacheMaxAge?: number; /** Timeout for JWKS request in milliseconds (default: 5 seconds) */ timeoutDuration?: number; }; } /** * Creates an OAuth2 Resource Server middleware for Elysia * * @example * ```typescript * app.use(oauth2ResourceServer({ * jwksUri: 'https://auth.example.com/.well-known/jwks.json', * issuer: 'https://auth.example.com', * audience: 'my-api' * })) * ``` */ export declare function oauth2ResourceServer(options: OAuth2ResourceServerOptions): (app: Elysia) => Elysia<"", { decorator: {}; store: {}; derive: { readonly bearer: any; }; resolve: {}; }, { error: {}; typebox: import("@sinclair/typebox").TModule<{}, {}>; }, { schema: {}; macro: {}; macroFn: {}; parser: {}; }, {}, { derive: {}; resolve: {}; schema: {}; }, { derive: { readonly auth: JWTPayload; }; resolve: {}; schema: {}; }>;