# Issue Token

> Issues a JWT signed with a Sommatic AI credential (recommended) or a literal secret.

Source: https://docs.sommatic.ai/en/nodes/token.issue/

- Slug: `token.issue`
- Family: Identity
- Version: 2.0.0
- Status: Available
- Execution: sync

Issues a JWT signed with a Sommatic AI credential (recommended) or a literal secret.

## Configuration

- `connection_id` (string, optional): Sommatic AI credential resolved server-side (recommended). Accepts credentials of type `jwt-signing`.
- `secret_key` (string, optional): Signing secret or private key as a literal. Allowed, but it is stored in the flow, its version history and Git: prefer connection_id.
- `payload` (object, required): Token claims
- `ttl_sec` (integer, optional): Default: `3600`.
- `algorithm` (string, optional): Default: `HS256`. Allowed values: `HS256`, `HS384`, `HS512`, `RS256`, `RS384`, `RS512`, `ES256`, `ES384`, `ES512`.

## Output ports

- `out` (default): Issued Token
- `error`: Issuance failed

## Input contract

- `connection_id` (string, optional)
- `secret_key` (string, optional)
- `payload` (object, required)
- `ttl_sec` (integer, optional)
- `algorithm` (string, optional)

## Output contract

- `token` (string, optional)
- `expires_at` (string, optional)

## In expressions

What a later node can read from this node's output with `$("Issue Token").item.json.<path>` (write your node's label instead of `Issue Token`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Issue Token").item.json.token` (string) = `"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWI…"`
- `$("Issue Token").item.json.expires_at` (string) = `"2026-11-26T15:19:05.000Z"`


## How it works

Signs a JWT with the claims you provide and an expiry of `ttl_sec` seconds. Supports HS256/384/512, RS256/384/512 and ES256/384/512; the key comes from a `jwt-signing` credential or a literal `secret_key`.

1. Resolves the config. Claims come from `payload`; when the node has no `payload` configured, the node input item is used as the claims.
2. Leaves through `error` with `payload is required` when the claims are missing or not an object.
3. Uses `ttl_sec` when it is a positive number, otherwise 3600 seconds.
4. Picks the key: `connection_id` first, otherwise the literal `secret_key`.
5. Signs with `algorithm` (default `HS256`); the token gets `iat` and `exp` claims.
6. Returns `{ token, expires_at }` on `out`, with `meta.crypto` and `meta.warnings`.

## In a workflow

### Node

```json
{
  "node_id": "node-issue-approval-token",
  "label": "Issue approval token",
  "operator_slug": "token.issue",
  "operator_version": "2.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "payload": {
      "sub": "{{ $json.user_id }}",
      "role": "approver"
    },
    "ttl_sec": 900,
    "algorithm": "HS256"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "out",
  "data": {
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfMTIzIiwicm9sZSI6ImFwcHJvdmVyIiwiaWF0IjoxNzk1NzI0MjEzLCJleHAiOjE3OTU3MjUxMTN9.<signature>",
    "expires_at": "2026-11-26T15:19:05.000Z"
  },
  "meta": {
    "crypto": {
      "op": "jwtSign",
      "key_source": "credential",
      "alias": "connection",
      "credential_id": "pi-credential-xxxx",
      "algorithm": "HS256",
      "ok": true
    },
    "warnings": []
  }
}
```

## Output ports (behaviour in the code)

### `out`

The token was signed.

```json
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfMTIzIiwicm9sZSI6ImFwcHJvdmVyIiwiaWF0IjoxNzk1NzI0MjEzLCJleHAiOjE3OTU3MjUxMTN9.<signature>",
  "expires_at": "2026-11-26T15:19:05.000Z"
}
```

### `error`

Claims are missing, the algorithm or key is not valid, or the credential cannot be resolved.

```json
{
  "error": "Unsupported JWT algorithm: PS256"
}
```

## Behaviour in the code

- `connection_id`: Takes precedence over `secret_key`. Resolved on the server when the node runs. A string secret is used as the key; an object secret is read as `private_key`, then `secret`, then `key`.
- `secret_key`: A literal key works, but it is stored in the flow, its version history and Git, and `meta.warnings` reports it on every run. Prefer `connection_id`.
- `payload`: Optional in practice: when it is not configured, the whole input item becomes the claims. Configure it explicitly to avoid signing fields you did not intend to.
- `ttl_sec`: Zero, negative or non-numeric values fall back to 3600. Every token expires; there is no option for tokens without `exp`.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `payload is required` | `error` | `payload` resolved to something that is not an object (a string, for example from mixed text). |
| `Unsupported JWT algorithm: <algorithm>` | `error` | `algorithm` is not one of the nine listed values. |
| `Bad "options.expiresIn" option the payload already has an "exp" property.` | `error` | The claims already contain `exp`. Remove it: the expiry always comes from `ttl_sec`. |
| `secretOrPrivateKey must be an asymmetric key when using <algorithm>` | `error` | An RS* or ES* algorithm was chosen with a shared secret. Use a PEM private key of the matching type. |
| `A key is required: pass { credential: "<alias>" } (recommended) or { key }` | `error` | Neither `connection_id` nor the literal key field is set. Select a credential in `connection_id`. |
| `credential binding 'connection' has no key usable for sign` | `error` | The credential resolved, but its secret is empty or is an object without a usable field. Store the key as a string, or as an object with the field this operation reads (see `connection_id`). |
| `Failed to resolve connection <connection_id>: <detail>` | `error` | The credential id does not exist or is not available to this workflow. Check the id and the credential type. |

## Notes and limits

- `expires_at` is computed from the worker clock right after signing, so it can differ from the token `exp` by a few milliseconds.
- Audience, issuer and subject cannot be set as options: put `aud`, `iss` or `sub` in the claims if you need them.
- Leaving through `error` does not fail the run: the engine follows the edges wired to `error`, and if there are none the branch simply ends.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "token.issue",
  "name": "Issue Token",
  "category": "identity",
  "version": "2.0.0",
  "description": "Issues a JWT signed with a Sommatic AI credential (recommended) or a literal secret.",
  "capabilities": [
    "authn",
    "jwt",
    "crypto"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "Signing credential",
        "description": "Sommatic AI credential resolved server-side (recommended). Accepts credentials of type `jwt-signing`.",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "jwt-signing"
          ]
        }
      },
      "secret_key": {
        "type": "string",
        "ui_widget": "password",
        "x-literal-secret": true,
        "description": "Signing secret or private key as a literal. Allowed, but it is stored in the flow, its version history and Git: prefer connection_id."
      },
      "payload": {
        "type": "object",
        "description": "Token claims"
      },
      "ttl_sec": {
        "type": "integer",
        "default": 3600
      },
      "algorithm": {
        "type": "string",
        "default": "HS256",
        "enum": [
          "HS256",
          "HS384",
          "HS512",
          "RS256",
          "RS384",
          "RS512",
          "ES256",
          "ES384",
          "ES512"
        ]
      }
    },
    "required": [
      "payload"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "secret_key": {
        "type": "string"
      },
      "payload": {
        "type": "object"
      },
      "ttl_sec": {
        "type": "integer"
      },
      "algorithm": {
        "type": "string"
      }
    },
    "required": [
      "payload"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "token": {
        "type": "string"
      },
      "expires_at": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Token",
      "description": "Issued Token",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Issuance failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "sync",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard"
  ],
  "tags": [
    "jwt",
    "auth"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_veripass",
    "profile": {
      "name": "Veripass",
      "verified": true,
      "url": "https://me.veripass.com/veripass",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string",
      "title": "Signing credential",
      "description": "Sommatic AI credential resolved server-side (recommended). Accepts credentials of type `jwt-signing`.",
      "ui_widget": "connection_picker",
      "ui_options": {
        "credential_types": [
          "jwt-signing"
        ]
      }
    },
    "secret_key": {
      "type": "string",
      "ui_widget": "password",
      "x-literal-secret": true,
      "description": "Signing secret or private key as a literal. Allowed, but it is stored in the flow, its version history and Git: prefer connection_id."
    },
    "payload": {
      "type": "object",
      "description": "Token claims"
    },
    "ttl_sec": {
      "type": "integer",
      "default": 3600
    },
    "algorithm": {
      "type": "string",
      "default": "HS256",
      "enum": [
        "HS256",
        "HS384",
        "HS512",
        "RS256",
        "RS384",
        "RS512",
        "ES256",
        "ES384",
        "ES512"
      ]
    }
  },
  "required": [
    "payload"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string"
    },
    "secret_key": {
      "type": "string"
    },
    "payload": {
      "type": "object"
    },
    "ttl_sec": {
      "type": "integer"
    },
    "algorithm": {
      "type": "string"
    }
  },
  "required": [
    "payload"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "token": {
      "type": "string"
    },
    "expires_at": {
      "type": "string"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Token",
    "description": "Issued Token",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Issuance failed",
    "is_default": false,
    "supports_condition": false
  }
]
```
