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.- migrate
- generate
3
Add the client plugin
auth-client.ts
Get a JWT token
Using the client plugin (recommended)
From the set-auth-jwt header
When you callgetSession, 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.
kid is received, fetch the JWKS again.
Verifying tokens
With remote JWKS (recommended)
With local JWKS
Configuration
Signing algorithm
The default algorithm isEdDSA 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
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 ajwks table to the database:
Private keys are encrypted with AES256 GCM by default. To disable encryption (not recommended):
jwt({ jwks: { disablePrivateKeyEncryption: true } })