JSON Web Token (JWT) is a popular method for implementing secure and stateless authentication and information exchange between parties. In this documentation, we will explore how to use JWT in the Helix project with the jwt-node
package.
Description
jwt-node
is a Node.js adaptation of the jwt-js
library for creating and verifying JSON Web Tokens. The latest version of jwt-node
is 0.2.0, published over 12 years ago. To install it, run npm i jwt
in your terminal. There are currently 2 other projects in the npm registry using jwt.
Official NPM Page GitHub Repository
Why Use JWT
JWT is used for securely transmitting information between parties as a JSON object. It is compact, digitally signed, and can be verified and processed by the client and server. JWT is ideal for stateless applications and APIs.
Example
Here’s an example of how to use JWT in your Helix project:
const jwt = require('jwt');
const payload = {
scope: 'client:outgoing?clientName=matt',
iss: 'APP_SID',
expires: Math.round((new Date().getTime() / 1000)) + 3600
};
const token = new jwt.WebToken(JSON.stringify(payload), JSON.stringify({typ: 'JWT', alg: 'HS256'}));
console.log(token.serialize('hmackey'));
In this example, we create a new JWT token with a payload containing the scope, issuer, and expiration time. The token is then serialized and logged to the console.
Installation
To install JWT in your Helix project, run the following command in your terminal:
npm install jwt
Known Issues
There are currently no known issues with the jwt-node
package.
Licenses
The jwt-node
package is licensed under the Mozilla Public License Version 1.1 (MPL), GNU General Public License Version 2 or later (GPL), or GNU Lesser General Public License Version 2.1 or later (LGPL). For more information, please refer to the LICENSE file in the project repository.
References
- Authentication with the API server | Kuma
- Checking Your Current Docker Pull Rate Limits and Status | Docker
- TLS Certificate Delegation and JWT Verification | ProjectContour
- Documentation | ProjectContour
- Use JWT as an OAuth 2.0 authentication provider | GitLab
- JWT Authentication — envoy tag-v1.11.2 documentation
- Service intentions configuration entry reference | Consul
- jwt_authn HTTP filter | ProjectContour
- JWT Authentication — envoy 1.17.0-5c801b documentation