AuthHandler provides a unified authentication layer supporting Bearer tokens,
API keys, and HTTP Basic Auth. All credential comparisons use constant-time
algorithms to prevent timing attacks. It can be used as Hono middleware or as a
standalone request validator.
Authentication configuration object with the following optional fields:
Bearer token matched against the Authorization: Bearer <token> header.
API key matched against the X-Api-Key header (or the custom header named
by config.apiKeyHeader).
Custom header name to use for API key lookup instead of the default
X-Api-Key. Lookup is case-insensitive.
Basic auth credentials as a [username, password] tuple.
Custom validator function. Return true to allow the request.
When explicitly set to false, deny requests if no auth methods are configured.
By default, unauthenticated access is allowed when no methods are set.
Validate request headers against all configured auth methods.
Create a Hono-compatible middleware that rejects unauthorized requests.
Create an Express/Connect-compatible middleware adapter.
Verify a username/password pair with constant-time comparison.
Verify a Bearer token with constant-time comparison.
Verify an API key with constant-time comparison.
Get metadata describing the enabled auth methods.
Check whether Bearer token authentication is configured.
Check whether API key authentication is configured.
Check whether Basic authentication is configured.