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

Inspect Token

解码并验证 JWT。

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

使用你提供的密钥校验 JWT 签名及时间声明,并返回声明和头部。未配置密钥时只解码令牌,并从 invalid 输出。

工作原理

  1. 解析配置;当 token 为空时,以 token is required 从 error 输出。
  2. 选择密钥:优先 connection_id,否则使用字面量 secret_key。
  3. 没有密钥时,不做校验直接解码令牌,从 invalid 返回其声明和头部,绝不会标记为有效。
  4. 否则仅允许 algorithm(默认 HS256)校验签名,并检查 exp 和 nbf。
  5. 有效时从 out 返回 { valid: true, verified: true, payload, header };无效时从 invalid 返回 { valid: false, verified: false, error }。

在工作流中

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

{
  "node_id": "node-verify-approval-token",
  "label": "Verify approval token",
  "operator_slug": "token.inspect",
  "operator_version": "2.0.0",
  "config": {
    "token": "{{ $json.token }}",
    "connection_id": "pi-credential-xxxx",
    "algorithm": "HS256"
  }
}

配置

token string 必填
connection_id string 可选

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

secret_key string 可选

可选的验证密钥

algorithm string 可选

默认值: HS256

可选值: HS256HS384HS512RS256RS384RS512ES256ES384ES512

代码中的行为

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

connection_id
优先于 secret_key,在节点运行时于服务端解析。字符串密钥直接使用;对象密钥依次读取 public_key、secret、key。
secret_key
字面量密钥可以使用,但会保存在流程、版本历史和 Git 中,并且每次运行都会在 meta.warnings 中报告。建议使用 connection_id。
algorithm
只接受一个算法。使用其他算法签名的令牌会走 invalid。

输出端口

out 默认

签名和时间声明均有效。

数据
{
  "valid": true,
  "verified": true,
  "payload": {
    "sub": "usr_123",
    "role": "approver",
    "iat": 1795724213,
    "exp": 1795725113
  },
  "header": {
    "alg": "HS256",
    "typ": "JWT"
  }
}
invalid

校验失败(签名错误、已过期、格式错误、算法不同),或未配置密钥。未配置密钥时,数据还会包含未经校验的 payload 和 header,且没有 meta。

数据
{
  "valid": false,
  "verified": false,
  "error": "jwt expired"
}
error

token 为空,或凭据无法解析。

数据
{
  "error": "token is required"
}

在表达式中

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

表达式EditorWorker
$("Inspect Token").item.json.validboolean= true
$("Inspect Token").item.json.verifiedboolean= true
$("Inspect Token").item.json.payloadobject= {…}
$("Inspect Token").item.json.headerobject= {…}
$("Inspect Token").item.json.errorstringworker 不返回:读取结果为 undefined —
$("Inspect Token").item.json.payload.substring编辑器不提示= "usr_123"—
$("Inspect Token").item.json.payload.rolestring编辑器不提示= "approver"—
$("Inspect Token").item.json.payload.iatnumber编辑器不提示= 1795724213—
$("Inspect Token").item.json.payload.expnumber编辑器不提示= 1795725113—
$("Inspect Token").item.json.header.algstring编辑器不提示= "HS256"—
$("Inspect Token").item.json.header.typstring编辑器不提示= "JWT"—

— Editor: 编辑器会提示它,但 worker 并不返回:读取结果为 undefined。

— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。

错误

消息 端口 原因与处理
token is required error token 为空。
invalid signature invalid 令牌使用了其他密钥签名。
jwt expired invalid exp 声明的时间已过。
jwt malformed invalid 该值不是 JWT(三段 base64url)。
invalid algorithm invalid 令牌头部使用的算法与 algorithm 不同。请把 algorithm 设为签发方使用的算法。
Signature not verified: no key configured invalid connection_id 和 secret_key 都未设置,因此只解码了令牌。
credential binding 'connection' has no key usable for verify invalid 凭据已解析,但其密钥为空,或是缺少可用字段的对象。请将密钥存为字符串,或存为包含本操作所读字段的对象(见 connection_id)。
Failed to resolve connection <connection_id>: <detail> error 凭据 id 不存在,或该工作流无权使用。请检查 id 和凭据类型。

输入契约

token string 必填
connection_id string 可选
secret_key string 可选
algorithm string 可选

输出契约

valid boolean 可选
verified boolean 可选
payload object 可选
header object 可选
error string 可选

契约(JSON Schema)

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

{
  "slug": "token.inspect",
  "name": "Inspect Token",
  "category": "identity",
  "version": "2.0.0",
  "description": "Verifies a JWT with a Sommatic AI credential (recommended) or a literal key. Without a key the token is never reported as valid.",
  "capabilities": [
    "authn",
    "jwt",
    "crypto"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "token": {
        "type": "string"
      },
      "connection_id": {
        "type": "string",
        "title": "Verification 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": "Verification secret or public key as a literal. Allowed, but it is stored in the flow, its version history and Git: prefer connection_id."
      },
      "algorithm": {
        "type": "string",
        "default": "HS256",
        "enum": [
          "HS256",
          "HS384",
          "HS512",
          "RS256",
          "RS384",
          "RS512",
          "ES256",
          "ES384",
          "ES512"
        ]
      }
    },
    "required": [
      "token"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "token": {
        "type": "string"
      },
      "connection_id": {
        "type": "string"
      },
      "secret_key": {
        "type": "string"
      },
      "algorithm": {
        "type": "string"
      }
    },
    "required": [
      "token"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "valid": {
        "type": "boolean"
      },
      "verified": {
        "type": "boolean"
      },
      "payload": {
        "type": "object"
      },
      "header": {
        "type": "object"
      },
      "error": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Token Data",
      "description": "Token is valid or decoded",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "invalid",
      "label": "Invalid",
      "description": "Verification failed",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Processing error",
      "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

说明与限制

  • 定义中把 out 描述为“有效或已解码”,但仅解码(无密钥)的令牌总是走 invalid。
  • 不会校验受众(aud)和签发者(iss):请在 out 之后用 flow.if 对 payload 自行比较。
  • 从 error 端口输出不会使运行失败:引擎沿 error 上的连线继续;若没有连线,该分支直接结束。

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

安装智能体工具

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

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

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