本页内容
Sommatic 文档
打开控制台

Issue Token

签发新的 JWT 访问令牌或会话令牌。

以 Markdown 查看
在以下应用中打开
身份 可用 token.issue 版本 2.0.0 执行方式: sync

用你提供的声明签发 JWT,有效期为 ttl_sec 秒。支持 HS256/384/512、RS256/384/512 和 ES256/384/512;密钥来自 jwt-signing 凭据或字面量 secret_key。

工作原理

  1. 解析配置。声明取自 payload;若节点未配置 payload,则把节点输入项作为声明。
  2. 当声明缺失或不是对象时,以 payload is required 从 error 输出。
  3. ttl_sec 为正数时使用该值,否则使用 3600 秒。
  4. 选择密钥:优先 connection_id,否则使用字面量 secret_key。
  5. 使用 algorithm(默认 HS256)签名;令牌会带上 iat 和 exp 声明。
  6. 从 out 返回 { token, expires_at },并附带 meta.crypto 和 meta.warnings。

在工作流中

节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。

{
  "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"
  }
}

配置

connection_id string 可选

Sommatic AI credential resolved server-side (recommended). Accepts credentials of type `jwt-signing`.

secret_key string 可选

签名密钥

payload object 必填

令牌声明(Claims)

ttl_sec integer 可选

默认值: 3600

algorithm string 可选

默认值: HS256

可选值: HS256HS384HS512RS256RS384RS512ES256ES384ES512

代码中的行为

除 schema 描述之外,实现代码对这些键的实际处理。

connection_id
优先于 secret_key,在节点运行时于服务端解析。字符串密钥直接使用;对象密钥依次读取 private_key、secret、key。
secret_key
字面量密钥可以使用,但会保存在流程、版本历史和 Git 中,并且每次运行都会在 meta.warnings 中报告。建议使用 connection_id。
payload
实际上可不填:未配置时,整个输入项会成为声明。建议显式配置,以免签入不想要的字段。
ttl_sec
零、负数或非数字值会回退为 3600。所有令牌都会过期,不支持不带 exp 的令牌。

输出端口

out 默认

令牌已签发。

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

声明缺失、算法或密钥无效,或凭据无法解析。

数据
{
  "error": "Unsupported JWT algorithm: PS256"
}

在表达式中

后续节点可通过 $("Issue Token").item.json.<路径> 读取此节点输出中的内容(请把 Issue Token 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 out 返回的路径,依据“端口”一节所示的输出。

表达式EditorWorker
$("Issue Token").item.json.tokenstring= "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWI…"
$("Issue Token").item.json.expires_atstring= "2026-11-26T15:19:05.000Z"

错误

消息 端口 原因与处理
payload is required error payload 解析结果不是对象(例如混合文本得到的字符串)。
Unsupported JWT algorithm: <algorithm> error algorithm 不在列出的九个值中。
Bad "options.expiresIn" option the payload already has an "exp" property. error 声明中已包含 exp。请删除它:过期时间始终由 ttl_sec 决定。
secretOrPrivateKey must be an asymmetric key when using <algorithm> error 选择了 RS* 或 ES* 算法却使用共享密钥。请使用对应类型的 PEM 私钥。
A key is required: pass { credential: "<alias>" } (recommended) or { key } error connection_id 和字面量密钥字段都未设置。请在 connection_id 中选择一个凭据。
credential binding 'connection' has no key usable for sign error 凭据已解析,但其密钥为空,或是缺少可用字段的对象。请将密钥存为字符串,或存为包含本操作所读字段的对象(见 connection_id)。
Failed to resolve connection <connection_id>: <detail> error 凭据 id 不存在,或该工作流无权使用。请检查 id 和凭据类型。

输入契约

connection_id string 可选
secret_key string 可选
payload object 必填
ttl_sec integer 可选
algorithm string 可选

输出契约

token string 可选
expires_at string 可选

契约(JSON Schema)

与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。

{
  "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
    }
  }
}

执行

执行方式
sync
有状态
否
能力
authnjwtcrypto
标签
jwtauth

说明与限制

  • expires_at 在签名后按 worker 时钟计算,可能与令牌的 exp 相差几毫秒。
  • 受众、签发者和主题无法作为选项设置:如有需要,请把 aud、iss 或 sub 放入声明中。
  • 从 error 端口输出不会使运行失败:引擎沿 error 上的连线继续;若没有连线,该分支直接结束。

已对照编排器代码核实 · 31e874b · 2026-11-26

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

安装 Sommatic AI CLI,并为检测到的智能体配置合适的插件。

npx @sommatic/cli agent setup
智能体如何读取本文档