0CodeKit icon

0CodeKit

A toolbox of no-code utilities

Actions132

Generate → Encode JSON Web Token

AI-generated

Overview

This node provides a utility to generate JSON Web Tokens (JWTs) by encoding a given JSON payload with a secret key. It supports specifying the signing algorithm and token expiration time. This is useful in scenarios where you need to create JWTs for authentication, authorization, or secure data exchange between services.

Practical examples include:

  • Generating access tokens for API authentication.
  • Creating signed tokens that carry user identity or session information.
  • Encoding claims securely to be verified later by another service.

Properties

Name Meaning
Payload The JSON string representing the data to encode inside the JWT. Example: {"sub": "1234567890", "name": "John Doe"}
Secret The secret key used to sign the token. This should be kept confidential.
Algorithm The cryptographic algorithm used for signing. Options: HS256, HS384, HS512
Expires In Optional expiration time for the token, e.g., "1h" (1 hour), "7d" (7 days), "30m" (30 minutes). If empty, token does not expire.

Output

The node outputs a JSON object containing the encoded JWT as a string. The output field typically looks like:

{
  "token": "<encoded JWT string>"
}

There is no binary output; the result is purely textual.

Dependencies

  • Requires an active connection to the external 0CodeKit API service at https://prod.0codekit.com.
  • Needs an API key credential configured in n8n to authenticate requests to this service.
  • No local cryptographic libraries are used; all encoding is done via the external API.

Troubleshooting

  • Invalid Payload Format: If the payload is not valid JSON, the API may return an error. Ensure the payload string is properly formatted JSON.
  • Incorrect Secret or Algorithm: Using an unsupported algorithm or incorrect secret might cause token generation failure.
  • Expired Token Misconfiguration: Providing an invalid format for the expiration time (e.g., "one hour" instead of "1h") can lead to errors.
  • API Authentication Errors: Missing or invalid API credentials will prevent the node from working.
  • Network Issues: Connectivity problems to the external API endpoint will cause execution failures.

To resolve these issues:

  • Validate JSON payload before input.
  • Use one of the supported algorithms exactly as listed.
  • Follow the expiration time format examples.
  • Verify API key configuration in n8n credentials.
  • Check network connectivity and proxy settings if applicable.

Links and References

Discussion