Skip to main content
Key0 provides access token validation middleware for every supported framework, plus a standalone validator for backend services that do not run the full SDK. All middleware functions extract the Bearer token from the Authorization header, verify it using the configured secret or public key, and attach the decoded payload to the request context. On failure they return a JSON error response and short-circuit the request.

Configuration Types

ValidateAccessTokenConfig

Used by the framework-specific middleware functions (validateAccessToken, honoValidateAccessToken, fastifyValidateAccessToken).

ValidatorConfig

Used by the standalone validateKey0Token function. Supports both HS256 and RS256.

AccessTokenPayload

All middleware functions resolve to the same decoded JWT payload shape.

Framework Middleware

validateAccessToken

Express middleware. On success, attaches the decoded payload to req.key0Token.
Signature:
Request property: req.key0Token (AccessTokenPayload)

Internal: validateToken

The framework-agnostic function used by validateAccessToken, honoValidateAccessToken, and fastifyValidateAccessToken. You do not need to call this directly unless you are building a custom integration.
Throws Key0Error with the following codes:

Error Responses

All framework middleware functions return a consistent JSON error body on failure: 401 — Missing, expired, or invalid token:
500 — Internal error (unexpected exception during verification):

Express Integration

Full setup guide for mounting Key0 routes and middleware in Express.

Backend Integration Example

Use validateKey0Token in a separate backend service.

AccessTokenIssuer

The JWT issuer whose tokens this middleware validates.