Protect Express API routes so only requests with a valid login token are allowed through
Decode JWT payload and make user identity available to downstream route handlers with no extra code
Support multiple token issuers or public-key signing by providing a dynamic key-retrieval function
Implement token revocation by hooking in a custom check that queries your database or cache
Requires an existing Express app and a JWT secret or public key, basic setup is a single middleware call.
This library is a piece of middleware for Express, a popular framework for building web servers in JavaScript. Its specific job is to check incoming requests for a JWT, which stands for JSON Web Token. A JWT is a small, self-contained string that a server hands out when a user logs in, and which that user then sends along with future requests to prove who they are. This library reads that token, validates it, and if it checks out, makes the user's identity information available to the rest of the application. Setting it up is straightforward for a developer. You add it as a step in your request-handling chain, pass it a secret key, and specify which signing algorithm to expect. From that point on, any route you protect with it will automatically reject requests that lack a valid token or carry one that has expired, been tampered with, or fails any other check. The decoded token data ends up on the request object, where your own code can read it to decide what a given user is allowed to do. The library covers several practical scenarios beyond the basics. If your application issues tokens using a public and private key pair rather than a shared secret, that is supported. You can provide a custom function that retrieves the verification key dynamically, which is useful when multiple issuers with different keys might be sending tokens. There is also support for checking whether a specific token has been revoked, for cases where you need to invalidate credentials before they naturally expire. Other options let you choose where in the request the token lives, skip authentication on certain routes using an unless helper, and configure how expired tokens are handled. If a token is invalid, the library throws an error that your existing Express error handler can catch and respond to however you prefer. The library is maintained by Auth0, a company that specializes in authentication services.
← auth0 on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.