注册 — 获取访问密钥/秘密密钥

这是工厂集成商要做的第一件事:向 TrustMint 注册一个“工厂服务”后端,并获取对每个后续调用进行签名的 access-key-id / secret-key 对。完成本演练后,您可以驱动 Thing 生命周期,轮询 API 参考 端点,并连接 webhooks。

本指南中的凭据是占位符。 无论您在何处看到 <your-access-key-id> 或 <your-secret-key>,请替换您从 201 响应中捕获的实际值。 永远不要提交真正的密钥 — SDK 示例将其写入 git 忽略的 .aksk.env(请参阅 SDK 快速入门)。

Step 0 — Your account, and the credential this guide assumes

Everything below runs under your account's own credential. You get it from the FlexGalaxy console:

  1. Your account is created by FlexGalaxy onboarding; sign in at the console as its root user.

  2. Service users → Create service user — this is the non-human identity your backend signs with. Open it, Create access key, and capture the access-key-id / secret-key shown once. Store them in your fgai profile: fgai auth service-user configure --name <profile> … (the CLI then signs every call).

  3. Attach the policies this identity needs (Access policies on the same page). A broad administrator policy does not imply the device capabilities — enrollment needs its own explicit grant (see Getting started §Step 3).

Then create the registrar your factory is built around (AK/SK-signed) — the factory-service below targets its registrar_id:

fgai provisioning registrars-create --body '{"name":"acme-robotics","display_name":"ACME Robotics"}'

Approving a registrar is a platform-operator decision, not a tenant one: the approval verbs are carried by fgai-admin, and your tenant CLI will not offer them. Create the registrar above, then wait for the FlexGalaxy operator to approve it; the steps below are what you do once it is approved.

步骤 1 — 注册工厂服务 (JWT-gated)

注册本身由承载 JWT(来自平台 IdP 的注册器管理员身份)进行控制,不是通过 AK/SK — 此时 AK/SK 还不存在。针对 Keycloak 创建一个注册器 JWT,然后:

POST /provisioning/v1/factory-integrations
Authorization: Bearer <registrar-admin-jwt>
Content-Type: application/json

{
  "registrar_id": "reg-acme-robotics",
  "model_id": "550e8400-e29b-41d4-a716-446655440000",
  "role": "identify",
  "endpoint_url": "https://factory.example.com/v1/identify"
}

201 Created 返回一次性凭证对:

{
  "id": "fs-...",
  "registrar_id": "reg-acme-robotics",
  "model_id": "550e8400-e29b-41d4-a716-446655440000",
  "role": "identify",
  "endpoint_url": "https://factory.example.com/v1/identify",
  "access_key_id": "<your-access-key-id>",
  "secret_access_key": "<your-secret-key>",
  "state": "active",
  "rotation_pending": false
}

role只是identify或provision。您实际实现的每个 (registrar_id, model_id, role) 元组注册一个后端。 endpoint_url 是该角色的 thingmake-to-factory HTTP 后端 URL,而不是面向设备的 DDI 端点。模型承载设备没有平台默认值或注册器范围内的后备。

secret_access_key 仅显示一次。立即捕捉;没有端点重新读取它。 Go 和 Python 01-register-factory-service 示例正是这样做的,并将该对持久保存到 .aksk.env — 请参阅 SDK 快速入门。

AK/SK 从哪里来?注册为您的工厂服务提供真正的 DotID 服务用户,并通过 DotID 的服务用户/访问密钥 API 为其颁发访问密钥。 secret_access_key 在这个 201 响应中 仅暴露了一次 — TrustMint 从不存储它(仅保留 access_key_id 加上 DotID 句柄;明文秘密列在 v2.11 秘密存储剪切中被删除)。 DotID 是发行机构,TrustMint 不持有任何工厂秘密。如果您丢失了秘密,则无法重新读取它 - 轮换凭证(它提供带有短宽限期的新访问密钥,再次返回新的秘密揭示一次)并重新捕获它。

如果注册被拒绝,则响应为application/problem+json,携带THM-NNNNN代码。基础身份验证代码(THM-101xx - JWT 过期/签名无效/丢失)位于 bucket 1 中;参见错误目录。

第 2 步 — 签署每个后续请求 (FGAI-HMAC-SHA256)

一旦您持有 <your-access-key-id> / <your-secret-key>,工厂服务运行时调用(/provisioning/v1/things/*、/provisioning/v1/state-changes、/api/v1/identity-blacklist*、订阅)将通过 FGAI-HMAC-SHA256 方案进行身份验证。

注册器管理调用,例如工厂服务注册和较新的设备模型注册表(/api/v1/thingmake/vendors、/registry/v1/models、/registry/v1/software)是由平台 IdP/PDP 控制的承载 JWT。在示例中保持这种分割可见:使用 JWT 创建或管理注册器资源;使用 AK/SK 进行工厂运行时回调和提要。

ℹ️ FGAI-HMAC-SHA256 是 SigV4 算法 — 但不兼容 aws-sdk

这是 AWS SigV4 派生密钥链算法,因此 SigV4 心理模型直接适用:kDate→kRegion→kService 签名密钥链、规范请求和携带 Credential / SignedHeaders / Signature 的 Authorization 标头。 但是它是FGAI品牌 - 链以fgai4_request(不是AWS的aws4_request)终止,方案名称是FGAI-HMAC-SHA256(不是AWS4-HMAC-SHA256)。因此,它与库存 aws-sdk 请求签名者不兼容。 不要将 aws-sdk 签名者连接到这些端点 - 它会产生签名 DotID 拒绝。 使用 FGAI SDK (below),它发出 FGAI 品牌的线字节。

规范请求(六个组件,\n 连接 — 字节与 DotID 的 SigV4HmacVerifier.canonicalRequest 相同):

canonical =
  METHOD                + "\n" +
  CANONICAL_PATH        + "\n" +   // "/" when empty
  CANONICAL_QUERY       + "\n" +   // sorted percent-encoded k=v, or "" when none
  CANONICAL_HEADERS     + "\n" +   // each "name:value\n", names lower-cased + sorted
  SIGNED_HEADERS        + "\n" +   // ";"-joined sorted lower-case names
  SHA256_HEX(BODY)

其中签名标头集是 host;x-fgai-content-sha256;x-fgai-date。

派生的签名密钥链(然后使用 kSigning 签署规范请求):

kSecret   = "FGAI4" + <your-secret-key>
kDate     = HMAC_SHA256(kSecret,  <yyyyMMdd>)
kRegion   = HMAC_SHA256(kDate,    "ap-northeast-1")
kService  = HMAC_SHA256(kRegion,  "thingmake")
kSigning  = HMAC_SHA256(kService, "fgai4_request")
signature = HEX(HMAC_SHA256(kSigning, canonical))

完整的配方——冻结范围文字和有效的黄金向量——随 SDK 签名助手一起提供;参见SDK快速入门。

每个签名请求发送的标头:

标头

值

Authorization

FGAI-HMAC-SHA256 Credential=<akid>/<yyyyMMdd>/ap-northeast-1/thingmake/fgai4_request, SignedHeaders=host;x-fgai-content-sha256;x-fgai-date, Signature=<64-lower-hex>

X-FGAI-Date

紧凑型 yyyyMMddTHHmmssZ UTC;必须在 ±5 分钟偏差窗口内

X-FGAI-Content-SHA256

请求正文的小写十六进制 SHA-256(等于规范组件 6)

你不应该**手卷这个。 SDK 签名者发出与服务器验证者字节相同的规范字符串:

  • 开始 — signing.NewSigningTransport(ak, sk, http.DefaultTransport)

  • Python — httpx.Client(auth=AKSKAuth(ak, sk)) 或 requests.Session() + AKSKAuthRequests(ak, sk)

有关签名助手,请参阅SDK 快速入门。

签名失败时

签名/身份验证失败返回 401 和 工厂身份验证 代码(THM-201xx,错误目录 的 存储桶 2):

代码

DotID 故障模式

含义

修复

THM-20110

MISSING_HEADER

缺少必需的签名标头 (Authorization / X-FGAI-Date / X-FGAI-Content-SHA256)

附加所有三个签名标头

THM-20120

INVALID_SIGNATURE

Signature 不匹配,或者 X-FGAI-Content-SHA256 ≠ 主体哈希

根据确切的规范请求+派生密钥重新计算

THM-20130

EXPIRED

X-FGAI-Date 在 ±5 分钟偏移窗口之外

用新鲜的X-FGAI-Date重新签名

THM-20140

UNKNOWN_KEY

Credential 中的访问密钥 ID 无法识别

确认 AK 是最新的 + 绑定到活动的工厂服务

THM-20150

REPLAY

重播了重复的 Authorization Signature

用新鲜的X-FGAI-Date重新签名

(THM-20100 是未分类签名失败的通用 factory-auth-failed 后备。)

Two more responses can come back on this path, and both are 503 rather than 401 because your credential was never evaluated — re-signing will not help:

代码

含义

修复

THM-20210

the signature verifier could not be reached

retry after a short backoff

THM-20220

the service's own credential to the verifier was refused

report it — this is a server-side defect, not a problem with your key

完整的bucket-2表(标题+描述)位于错误目录中。

接下来做什么

  • 接收事物状态通知 → Webhooks

  • 端到端运行所有四个步骤 → 入门

  • 自我认证您的后端 → 一致性