Inspect Token
解码并验证 JWT。
使用你提供的密钥校验 JWT 签名及时间声明,并返回声明和头部。未配置密钥时只解码令牌,并从 invalid 输出。
工作原理
- 解析配置;当
token为空时,以token is required从error输出。 - 选择密钥:优先
connection_id,否则使用字面量secret_key。 - 没有密钥时,不做校验直接解码令牌,从
invalid返回其声明和头部,绝不会标记为有效。 - 否则仅允许
algorithm(默认HS256)校验签名,并检查exp和nbf。 - 有效时从
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"
}
}{
"ok": true,
"port": "out",
"data": {
"valid": true,
"verified": true,
"payload": {
"sub": "usr_123",
"role": "approver",
"iat": 1795724213,
"exp": 1795725113
},
"header": {
"alg": "HS256",
"typ": "JWT"
}
},
"meta": {
"crypto": {
"op": "jwtVerify",
"key_source": "credential",
"alias": "connection",
"credential_id": "pi-credential-xxxx",
"algorithm": "HS256",
"ok": true
},
"warnings": []
}
}配置
-
tokenstring 必填 -
connection_idstring 可选 -
Sommatic AI credential resolved server-side (recommended). Accepts credentials of type `jwt-signing`.
-
secret_keystring 可选 -
可选的验证密钥
-
algorithmstring 可选
代码中的行为
除 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 返回的路径,依据“端口”一节所示的输出。
| 表达式 | Editor | Worker |
|---|---|---|
$("Inspect Token").item.json.valid | ||
$("Inspect Token").item.json.verified | ||
$("Inspect Token").item.json.payload | ||
$("Inspect Token").item.json.header | ||
$("Inspect Token").item.json.error | — | |
$("Inspect Token").item.json.payload.sub | — | |
$("Inspect Token").item.json.payload.role | — | |
$("Inspect Token").item.json.payload.iat | — | |
$("Inspect Token").item.json.payload.exp | — | |
$("Inspect Token").item.json.header.alg | — | |
$("Inspect Token").item.json.header.typ | — |
— 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 和凭据类型。 |
输入契约
-
tokenstring 必填 -
connection_idstring 可选 -
secret_keystring 可选 -
algorithmstring 可选
输出契约
-
validboolean 可选 -
verifiedboolean 可选 -
payloadobject 可选 -
headerobject 可选 -
errorstring 可选
契约(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
}
}
}{
"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"
]
}{
"type": "object",
"properties": {
"token": {
"type": "string"
},
"connection_id": {
"type": "string"
},
"secret_key": {
"type": "string"
},
"algorithm": {
"type": "string"
}
},
"required": [
"token"
]
}{
"type": "object",
"properties": {
"valid": {
"type": "boolean"
},
"verified": {
"type": "boolean"
},
"payload": {
"type": "object"
},
"header": {
"type": "object"
},
"error": {
"type": "string"
}
}
}[
{
"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
}
]执行
- 执行方式
sync- 有状态
- 否
- 能力
authnjwtcrypto- 标签
jwtauth
说明与限制
- 定义中把
out描述为“有效或已解码”,但仅解码(无密钥)的令牌总是走invalid。 - 不会校验受众(
aud)和签发者(iss):请在out之后用flow.if对payload自行比较。 - 从
error端口输出不会使运行失败:引擎沿error上的连线继续;若没有连线,该分支直接结束。
已对照编排器代码核实 · 31e874b · 2026-11-26