Skip to main content
The JWT plugin provides endpoints to retrieve a JWT token and a JWKS endpoint for token verification. It is intended for service-to-service authentication and APIs that require JWT tokens rather than session cookies.
This plugin is not a replacement for sessions. For API requests that need to read session tokens as Bearer tokens, the Bearer plugin handles that use case.

Installation

1

Add the plugin to your auth config

auth.ts
2

Migrate the database

Run the migration or generate the schema to add the JWKS table.
3

Add the client plugin

auth-client.ts

Get a JWT token

From the set-auth-jwt header

When you call getSession, a JWT is returned in the set-auth-jwt response header:

Direct HTTP request

JWKS endpoint

The JWKS endpoint is available at /api/auth/jwks and publishes the public key used to sign tokens.
The public key can be cached indefinitely. When a JWT with a different kid is received, fetch the JWKS again.

Verifying tokens

With local JWKS

Configuration

Signing algorithm

The default algorithm is EdDSA with the Ed25519 curve. Other supported algorithms:

Customize the JWT payload

By default the full user object is added to the JWT payload. Restrict it:
auth.ts

Issuer, audience, and expiration

auth.ts

Key rotation

auth.ts

Custom JWKS path

auth.ts
When using a custom path, configure the client to match:
auth-client.ts

Remote JWKS URL

Disables the local /jwks endpoint and uses an external URL instead:
auth.ts

Custom adapter

Store JWKS in a location other than your primary database (e.g., Redis):
auth.ts

OAuth provider mode

If you are using the OIDC or OAuth provider plugins alongside JWT, disable the conflicting /token endpoint:
auth.ts

Schema

The JWT plugin adds a jwks table to the database:
Private keys are encrypted with AES256 GCM by default. To disable encryption (not recommended): jwt({ jwks: { disablePrivateKeyEncryption: true } })