Actions2
Overview
This node provides functionality to generate and verify JSON Web Tokens (JWTs). It is useful in scenarios where secure token-based authentication or data exchange is required. For example, you can use it to create a signed JWT containing user information for authentication purposes or verify an incoming JWT to ensure its validity and integrity.
The node supports two main operations:
- Generate JWT: Creates a JWT from a given payload using a private key.
- Verify JWT: Validates a JWT against a private key and optionally extends the input data with verification results or raises exceptions on errors.
Properties
| Name | Meaning |
|---|---|
| Operation | Choose between "Generate JWT" or "Verify JWT" operation. |
| Payload | The JSON data object or string to encode into the JWT (required for both operations). |
| Target Object Name | The key name under which the result (generated token or verification output) will be stored in the output JSON. Default is "result". |
| Private Key | The private key used to sign or verify the JWT. |
| Options (Verify JWT only) | Modifiers for verification behavior: - Raise Exception: Whether to throw an error if verification fails (boolean). - Extend Input Object: Whether to add verification results to each input item instead of returning a new output (boolean). |
Output
The node outputs JSON data with a single key defined by the "Target Object Name" property. The value depends on the operation:
Generate JWT: The output contains the generated JWT string.
Example:
{ "result": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." }Verify JWT: The output contains the decoded JWT payload along with metadata if verification succeeds, or an error indicator if it fails.
Example success output:
{ "result": { "header": { ... }, "payload": { ... }, "signature": "...", "error": false } }If verification fails and "Raise Exception" is false, the output will be:
{ "result": { "error": true } }
If "Extend Input Object" is enabled during verification, the verification result is merged into each input item's JSON under the specified target key.
The node does not output binary data.
Dependencies
- Requires the
jsonwebtokenlibrary for JWT signing and verification. - Needs a valid private key string for signing or verifying tokens.
- No external API calls or services are required.
- No special environment variables or n8n credentials beyond providing the private key as a string.
Troubleshooting
Error: "Payload must be defined in type string or object"
Occurs if the payload is missing or empty when generating a JWT. Ensure the payload property is set correctly.Verification failures
If the JWT cannot be verified (e.g., invalid token, wrong key), the node either returns an error object or throws an exception depending on the "Raise Exception" option. To debug, check that the private key matches the one used to sign the token and that the token is well-formed.Invalid private key
Using an incorrect or malformed private key will cause signing or verification to fail. Verify the key format and correctness.JSON parsing issues
The payload should be a valid JSON string or object. Invalid JSON may cause unexpected errors.
Links and References
- jsonwebtoken npm package — Library used internally for JWT operations.
- JWT Introduction — Overview of JSON Web Tokens.
- JWT Debugger — Tool to decode, verify, and generate JWTs interactively.