Files
SnowLuma/.pnpm-store/v11/files/ab/9131123da81b9e4e5f7cb9346dc9c6b578ca2d94763e453c3fafa6f369b293cf9f7a869a0c90bb8cfd3fd5f088c5c2e5087b292f63d7f7c2bde2804d3c91c9
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

53 lines
2.9 KiB
Plaintext

import { MiddlewareHandler } from "../../types.js";
import { Context } from "../../context.js";
import { CookiePrefixOptions } from "../../utils/cookie.js";
import { AsymmetricAlgorithm } from "../../utils/jwt/jwa.js";
import { HonoJsonWebKey } from "../../utils/jwt/jws.js";
import { VerifyOptions } from "../../utils/jwt/jwt.js";
//#region src/middleware/jwk/jwk.d.ts
/**
* JWK Auth Middleware for Hono.
*
* @see {@link https://hono.dev/docs/middleware/builtin/jwk}
*
* @param {object} options - The options for the JWK middleware.
* @param {HonoJsonWebKey[] | ((ctx: Context) => Promise<HonoJsonWebKey[]> | HonoJsonWebKey[])} [options.keys] - The public keys used for JWK verification, or a function that returns them.
* @param {string | ((ctx: Context) => Promise<string> | string)} [options.jwks_uri] - If set to a URI string or a function that returns a URI string, attempt to fetch JWKs from it. The response must be a JSON object containing a `keys` array, which will be merged with the `keys` option.
* @param {boolean} [options.allow_anon] - If set to `true`, the middleware allows requests without a token to proceed without authentication.
* @param {string} [options.cookie] - If set, the middleware attempts to retrieve the token from a cookie with these options (optionally signed) only if no token is found in the header.
* @param {string} [options.headerName='Authorization'] - The name of the header to look for the JWT token. Default is 'Authorization'.
* @param {string} [options.realm] - The protection space described by the `realm` parameter of the returned `WWW-Authenticate` challenge header. Defaults to the request URL.
* @param {AsymmetricAlgorithm[]} options.alg - An array of allowed asymmetric algorithms for JWT verification. Only tokens signed with these algorithms will be accepted.
* @param {RequestInit} [init] - Optional init options for the `fetch` request when retrieving JWKS from a URI.
* @param {VerifyOptions} [options.verification] - Additional options for JWK payload verification.
* @returns {MiddlewareHandler} The middleware handler function.
*
* @example
* ```ts
* const app = new Hono()
*
* app.use("/auth/*", jwk({
* jwks_uri: (c) => `https://${c.env.authServer}/.well-known/jwks.json`,
* headerName: 'x-custom-auth-header', // Optional, default is 'Authorization'
* }))
*
* app.get('/auth/page', (c) => {
* return c.text('You are authorized')
* })
* ```
*/
export declare const jwk: (options: {
keys?: HonoJsonWebKey[] | ((ctx: Context) => Promise<HonoJsonWebKey[]> | HonoJsonWebKey[]);
jwks_uri?: string | ((ctx: Context) => Promise<string> | string);
allow_anon?: boolean;
cookie?: string | {
key: string;
secret?: string | BufferSource;
prefixOptions?: CookiePrefixOptions;
};
headerName?: string;
alg: AsymmetricAlgorithm[];
realm?: string;
verification?: VerifyOptions;
}, init?: RequestInit) => MiddlewareHandler;
//#endregion