API 认证与 JWT 校验

The platform's external authentication model — which host and route admit FGAI-HMAC-SHA256, which admit an OIDC bearer token, and the exact refusal for the other scheme — is stated once in External authentication model. This page covers the second half of that model: how a receiving service validates a bearer token it IS declared to accept.

JWT bearer authentication applies to browser/BFF flows and explicit service-audience workload contracts. It is not the CLI or public tenant-control-plane credential. Human bearer tokens, including platform-admin tokens, are never CLI credentials; platform administration remains private to the admin-console web app.

See CLI authentication for the signed public-API contract.

Authorization Code + PKCE 流程

无论是 FlexGalaxy.AI 自有应用还是第三方集成,规范流程都是 Authorization Code with PKCE (S256)。

  1. 应用生成 PKCE 的 code_verifier(密码学随机,长度 43-128 字符),并据此计算 code_challenge = BASE64URL(SHA256(code_verifier))。

  2. The user agent is redirected to the realm authorization endpoint, https://auth.flexgalaxy.ai/auth/realms/<realm>/protocol/openid-connect/auth:

    ?response_type=code
      &client_id=<your-client-id>
      &redirect_uri=<your-registered-redirect-uri>
      &scope=openid+profile+email
      &state=<csrf-token>
      &code_challenge=<challenge>
      &code_challenge_method=S256
    
  3. 用户通过 DotID 完成认证(PassPort + MFA,如需要)。

  4. DotID 携带 ?code=<auth-code>&state=<csrf-token> 重定向回你注册的 URI。请校验 state 与你发出时一致。

  5. Your application exchanges the code for tokens at https://auth.flexgalaxy.ai/auth/realms/<realm>/protocol/openid-connect/token:

    POST <realm-token-endpoint>
    Content-Type: application/x-www-form-urlencoded
    
    grant_type=authorization_code
    &code=<auth-code>
    &redirect_uri=<same-uri-as-step-2>
    &client_id=<your-client-id>
    &client_secret=<secret>           # confidential clients only
    &code_verifier=<original-verifier>
    
  6. DotID 返回 access_token、id_token,以及(若申请了 offline_access 范围)refresh_token。三者均为 JWT。

The access_token is presented only to the browser/BFF or explicitly registered service-audience surface as Authorization: Bearer <token>. It is not pasted into or stored by the FGAI CLI. The id_token is for your own application to learn who the user is. The refresh_token is exchanged at the same /token endpoint with grant_type=refresh_token.

Realm

DotID issues tokens from named realms on the platform Keycloak. Each realm issues its own JWTs from its own signing key.

Realm

适用主体

issuer claim 示例

flexgalaxy

The single tenant entry realm — account-root users, workforce members of accounts, and the platform-level workforce

https://auth.flexgalaxy.ai/auth/realms/flexgalaxy

Every account and organization is resolved inside flexgalaxy — tenancy rides token claims (account_id, user_type, org membership), never a realm name. The legacy per-account (acc-*) and per-org (idc-*) realm model was retired: those realms no longer exist and a token claiming an acc-*/idc-* issuer cannot be validly issued today. The platform additionally operates dedicated gate realms for its own surfaces (fgai-admins for platform administration, staging-access for the staging gate, insider-doc-viewers for the insider portal) — your service accepts those only if it is one of those platforms. Account-owned service users are non-interactive and use the Account boundary. These identity populations are isolated and are never merged by matching email.

租户绑定:account_id 和 user_type 声明

flexgalaxy realm 发出的访问令牌携带两个声明,用于描述已认证 subject 的租户绑定:account_id 和 user_type。

{
  "iss": "https://auth.flexgalaxy.ai/auth/realms/flexgalaxy",
  "sub": "9e0f6f96-2f57-4f49-84ef-8d4d12d4f5e1",
  "account_id": "11111111-1111-1111-1111-111111111111",
  "user_type": "root"
}
  • account_id — the DotID account UUID the subject is bound to. It is emitted for both account-root users and workforce members of an account. It means "this user belongs to this tenant" — nothing more. It is not the account name and not a realm name.

  • user_type — subject 如何绑定到该账户:

    • root — 账户的 root 用户。

    • workforce — 账户的 workforce 成员。

规则:

  • 严格从 user_type == "root" 推导账户 root 状态。 不要仅因存在 account_id 就推断为 root — workforce 用户同样携带 account_id,但不是 root。把“有 account_id”当成“是 root”会静默地把每个 workforce 成员提升为等同 root。

  • 使用 account_id 解析调用方的租户(用于每请求作用域限定以及构建 PDP principal 上下文)。不要从邮箱、用户名或 realm 名称推导账户身份。

  • 未绑定的 flexgalaxy 用户(例如平台管理员)两个声明都不会收到。如果 account_id 缺失,调用方未绑定到租户;如果 user_type 缺失或不是 root,不要将调用方视为账户 root。改为通过适当的平台管理员、workforce、服务用户或 workload 身份路径路由请求。

这些声明是身份上下文,不是授权授予。它们告诉服务已验证令牌属于哪个租户,以及 subject 是否是该账户的 root;它们并不表示调用方可以执行某个特定服务操作。第一方服务仍必须对任何由策略控制的账户/资源操作调用 DotID PDP。

校验服务收到的 JWT

A receiving service accepts a JWT only where the declaration in External authentication model admits one: a bearer surface, or a route the route table marks fgai-hmac+bearer, bearer or workload-jwt. Public tenant routes on the API edge implement the signed AK/SK and STS path (temporary ASIA credentials, available to any principal via sts assume-role); JWT support on another audience does not satisfy that public contract, and on an HMAC-only route the service refuses the bearer rather than validating it.

具体而言,你的 JWT 校验器必须:

  1. 从 token header / payload 中提取 iss claim。

  2. Verify the issuer is the platform realm — exact match: https://auth.flexgalaxy.ai/auth/realms/flexgalaxy. Reject any other issuer. Do not prefix-match realm families: the legacy acc-*/idc-* families no longer exist, and an exact match is what rejects a rogue realm that merely shares a prefix.

  3. 从 <issuer>/protocol/openid-connect/certs 拉取该 realm 的 JWKS。缓存这些密钥(DotID 会按计划轮换;请遵循 Cache-Control header)。

  4. 根据 JWKS 校验签名,按 token 的 kid header 匹配密钥。

  5. 校验标准 claim: exp(未过期)、nbf(若存在,未早于生效时间)、iat(结合时钟偏移做合理性检查)、aud(匹配你服务的受众标识)。

  6. 校验授权逻辑所依赖的任何服务专属 claim(例如 realm_access.roles、groups)。

DotID's own services implement exactly this pattern. There is exactly one customer-facing issuer, so a validator is a single exact-match check on flexgalaxy — there is no open-acceptance or prefix-allowlist variant to choose between, and none to mix.

AuthorizeRequest / AuthorizeResponse 结构

从你的 service 调用 DotID Policy Decision Point(PDP)使用固定的 request/response contract。

PDP 调用是授权步骤。JWT 校验回答的是“这个 token 是否真实、当前有效、由 DotID 颁发,并且面向此服务?”PDP 回答的是“这个 principal 是否可以在此账户中对该资源执行这个 action?”

不要因为 token 带有 account_id 就跳过 PDP。DotID 集中执行策略评估,使每个自有服务在托管策略、权限集、权限边界、服务控制策略、委派管理、资源策略以及 root-user 账户所有权方面都观察到相同的行为。如果每个服务都在本地重新实现这些检查,服务之间的策略行为将产生偏差。

最小请求:

{
  "principal": {
    "account_id": "11111111-1111-1111-1111-111111111111",
    "user_id": "u-12345",
    "user_type": "iam",
    "ic_session": false,
    "ps_id": null
  },
  "action": "licensing:Device:Read",
  "resource": "frn:11111111-1111-1111-1111-111111111111:licensing:device/dev-12345",
  "context": {
    "source_ip": "203.0.113.42",
    "request_time": "2026-05-25T11:00:00Z"
  }
}

最小响应:

{
  "decision": "ALLOW",
  "reason": null,
  "matched_statement": "AllowDeviceRead",
  "evaluation_time_ms": 2
}

decision 始终为 ALLOW 或 DENY。允许时 reason 为 null,拒绝时则为稳定的机器可读代码;matched_statement 是匹配的策略语句 Sid,没有语句匹配时为 null。DotID 使用 snake_case JSON 名称序列化 Java record 字段。

Discovering this resource (RFC 9728)

A 401 from a bearer-admitting surface — a browser host, or a machine route declared fgai-hmac+bearer, bearer or workload-jwt — names where to find this resource's OAuth 2.0 protected-resource metadata:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://api.flexgalaxy.ai/.well-known/oauth-protected-resource"

A 401 from an HMAC-only machine route does NOT carry that challenge. It challenges the credential the route actually accepts:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: FGAI-HMAC-SHA256 realm="dotid"

The distinction is deliberate: following an OAuth discovery pointer from a route that refuses OAuth bearer tokens sends a client to a credential exchange that cannot succeed there. The public metadata document still exists and is still anonymous — it just is not advertised by a route that will not accept what it describes.

Fetch that URL to get the RFC 9728 metadata document for the host you called:

curl -sS https://api.flexgalaxy.ai/.well-known/oauth-protected-resource
{
  "resource": "https://api.flexgalaxy.ai",
  "bearer_methods_supported": ["header"]
}

Those are the two fields a client needs; the document also carries the other RFC 9728 registry fields. The advertised URL is always https, always carries no port, and always names the host your request carried — a client may follow it as-is. The document is public: discovery precedes authentication, so it needs no credential.

FlexGalaxy.AI is multi-tenant, but tenancy is carried in token claims rather than separate realms: every account authenticates against the single platform realm, so the metadata document deliberately does not enumerate authorization servers. The authorization server is the platform realm — use its /.well-known/openid-configuration.

常见错误

状态

含义

排查方向

401 Unauthorized

The credential is absent, invalid, or of the wrong family for this route.

On JWT-bearing browser/workload routes, verify the bearer token's iss/kid; on public API-edge routes, verify the FGAI-HMAC signature and required STS session token. external-auth-scheme-mismatch means the route does not admit the family you sent — read the external authentication model instead of retrying with the same credential.

403 Forbidden

token 校验通过,但 PDP 返回了 DENY。

检查响应体 —— 它包含 reason,并在可获取时附带 matched_statement,用于追溯拒绝原因。

400 Bad Request(PDP)

principal 对象、action 或 resource FRN 不合法。

规范资源语法与解析方法参见 FRN 格式。

400 Bad Request(DotID API)

API 版本不匹配 —— 请求被发送到了已废弃的路径。

面向开发者的公共 API 使用 /<capability>/v1/...;自有控制台 API 使用各自的网关前缀。除非 ADR 列出了明确的网关例外,否则服务本地实现路径不属于公共 API。

联合工作负载 token

DotID 还会通过 RFC 8693 token exchange 为从外部 OIDC issuer(GitHub Actions、GitLab CI)联合而来的工作负载身份颁发 access token。你的服务对其执行的校验与校验任何其他 DotID 颁发的 JWT 相同:相同的 realm JWKS、相同的 iss / aud / exp 规则。唯一的区别是,token 的 sub 是 DotID 工作负载身份 ID,而不是 human 或 service-user ID,并且 token 还带有一个额外的 federated_subject 自定义 claim,形状为 {issuer, sub},用于记录来源 CI subject 以便进行审计关联。

仅将 federated_subject claim 视为审计元数据,绝不要将其用于授权决策。与其他所有 DotID 颁发的 token 一样,aud、sub 和 scope claim 才是授权边界。

有关交换契约(即 CI 调用以获取此 token 的端点,而不是你的服务为消费它所做的校验),请参见 workload-federation.md。