express-jwt validates JWTs in Express apps and attaches the decoded payload to the request for protected routes.
Overview
express-jwt provides Express middleware that validates JSON Web Tokens using the jsonwebtoken library. After successful validation, the decoded payload is available on the request object, defaulting to the auth property in current versions.
Configuration requires a secret or asynchronous key resolver and an explicit algorithms list to avoid downgrade issues. Optional audience and issuer checks are recommended. Tokens are read from the Authorization header by default, but custom getToken functions support cookies or query parameters.
Advanced options include dynamic secret lookup, secret rotation, revocation checks via isRevoked, custom handling for expired tokens, and credentialsRequired to allow anonymous access on some routes. express-unless patterns limit middleware to specific paths.
The module supports symmetric secrets and public-key verification for RS256-style tokens. TypeScript typings extend Express Request with auth. Migration notes document renamed imports and property changes from earlier major versions.
Key features
- JWT validation middleware
- Custom token extractors
- Dynamic secret retrieval
- Token revocation hook
- Path-specific unless rules
- Public key verification
- TypeScript request typings
- Optional credentials mode
Use cases
- Protecting Express API routes
- OAuth2 bearer token APIs
- Per-route authentication
- Multi-issuer JWT validation
- Revoked session handling