DotID 外部开发者 API 示例¶
本示例展示第三方开发者如何通过 APaaS 公共 API 网关将应用与 DotID 集成。
示例应用是 Acme Vision,一款虚构的组件摄像头分析产品。Acme Vision 希望:
将自身注册为第三方 APaaS 应用;
暴露应用专属的 scope;
通过 PassPort 请求 OIDC 浏览器登录;
发布 IAM action 和托管的 permission set;
发布配额定义;
发布审计事件分类体系;
可由 Account 或 Organization 管理员安装;
在用户进入应用时验证 PassPort launch ticket。
本示例说明 clean external developer API model。它有意不讲解旧版注册端点、client-registry 或原始 Keycloak Admin API。
可运行代码¶
可运行示例位于:
examples/external-developer-api/
It is a dependency-free Node.js client that performs its integration calls through the published external API below — developer registration, review status, service catalog, tenant installation, and PassPort app entry — using a developer OIDC credential.
本示例使用简洁的公共 capability API 名称:
/developer/v1/...
/service-catalog/v1/...
/accounts/v1/...
/organizations/v1/...
/passport/v1/...
架构¶
外部开发者绝不调用 Keycloak Admin API,也绝不直接写入 DotID 子系统表。
公共流程如下:
Developer tool
-> public API gateway
-> developer API
-> platform review
-> service catalog publication
-> tenant installation
-> scoped provisioning
-> PassPort app entry
-> third-party application
不允许的流程如下:
Developer tool
-> Keycloak Admin API
-> tenant realm mutation
Keycloak 是由平台负责的实现依赖。开发者描述所需的集成;平台负责审批、预配、审计并协调最终状态。
主机名¶
环境 |
Base URL |
|---|---|
生产环境 |
控制台入口与 API 面是分离的:
tenant console: https://console.flexgalaxy.ai
platform admin console: https://admin-console.flexgalaxy.ai
浏览器控制台测试使用控制台主机名。外部开发者 API 测试使用 API base URL。
参与者模型¶
本示例使用四类参与者。
参与者 |
说明 |
|---|---|
开发者 |
构建并注册 Acme Vision。使用开发者 API 凭证。 |
平台审核员 |
Platform admin who approves or rejects registrations. |
租户管理员 |
安装 Acme Vision 的 Account 或 Organization 管理员。 |
应用用户 |
通过 PassPort launch link 进入 Acme Vision 的用户。 |
认证模型¶
Developer API 使用平台签发的开发者凭证,而不是 Keycloak Admin token。
该 API 合约假定 bearer token 携带等效于以下内容的声明:
{
"iss": "<identity-issuer-url>",
"sub": "developer/acme",
"aud": "developer-api",
"developer_id": "acme",
"scope": "developer.services:write developer.services:read"
}
For production, the issuer is https://identity.flexgalaxy.ai.
生命周期¶
External registration is not self-publishing. The implemented lifecycle is:
DRAFT
-> in review (PENDING)
-> approved / rejected
-> active (provisioned, installable) / failed
-> retired (on unregister)
含义:
状态 |
含义 |
|---|---|
|
开发者可以编辑该注册。租户不可见。 |
|
Submitted for platform review; the version is frozen until the reviewer decides. Not visible to tenants. |
|
The platform reviewer's verdict. |
|
Approved registration, provisioned and visible in the service catalog; tenants can install it. |
|
Rejected, or provisioning failed; not in the catalog. |
|
Removed from the catalog by the developer after uninstall. |
Creating a registration submits it for review in the same call, so a fresh
registration is a draft pending review (in_review), never directly active.
The review outcome is a platform-side decision — a developer cannot approve or
reject their own registration. Deleting a registration retires it once no
active tenant installations remain.
Tenant installation is a separate lifecycle. A registration becoming active does not install it into every Account or Organization.
A registration's review states are draft, in_review, approved,
rejected, published, and retired (see the review endpoint below). A
freshly submitted registration starts as a draft pending review and becomes
installable once a platform reviewer approves it.
目标 API 面¶
面向开发者的 API¶
面向开发者的 API 位于:
/developer/v1
初始目标端点:
方法 |
路径 |
用途 |
|---|---|---|
|
|
Create and submit a service registration manifest for platform review. The registration starts as a draft pending review and becomes installable only after a platform reviewer approves it. |
|
|
列出归该开发者所有的 service。 |
|
|
获取最新的 service registration。 |
|
|
Resubmit a service registration manifest. The create call already submits for review; an already-submitted version is refused as immutable. |
|
|
Fetch the current review state — |
|
|
当不再存在活跃租户安装时,退役该 service registration。 |
Review is a platform-side decision, not a developer API call. When a platform
reviewer approves a registration, it is provisioned, becomes ACTIVE, and is
listed in the service catalog where tenants can install it; a rejection ends it
as FAILED. Developer clients never drive the review step for their own
registrations.
租户安装 API¶
租户安装 API 面向 Account 和 Organization 管理员公开:
/accounts/v1/{account_id}/service-installations
/organizations/v1/{org_id}/service-installations
初始目标端点:
方法 |
路径 |
用途 |
|---|---|---|
|
|
列出此参与者可安装的已发布 service。 |
|
|
查看权限、scope、配额和条款。 |
|
|
为独立 Account 安装。 |
|
|
列出独立 Account 的活跃 service installation。 |
|
|
为 Organization 安装。 |
|
|
列出 Organization 的活跃 service installation。 |
|
|
轮询安装/预配状态。 |
|
|
卸载并取消预配限定范围内的 artifact。 |
PassPort 运行时 API¶
PassPort 运行时 API 位于:
/passport/v1
当前已实现的端点包括:
方法 |
路径 |
用途 |
|---|---|---|
|
|
获取已注册应用的元数据。 |
|
|
创建 launch link。 |
|
|
认证后兑换 launch token。 |
|
|
验证绑定到应用的 launch ticket。 |
developer registration API 会间接创建或更新 PassPort 应用记录。开发者不应直接写入 PassPort 表。GET /passport/v1/applications/{app_id} 的 smoke test 必须提供目标环境中存在的 app ID。
示例 service manifest¶
Acme Vision 提交一个 service registration manifest。
{
"manifestVersion": "1.0.0",
"serviceId": "acme-vision",
"displayName": "Acme Vision",
"description": "Computer vision analytics for widget cameras.",
"surfaces": {
"iam": {
"service_id": "acme-vision",
"display_name": "Acme Vision",
"actions": [
{
"name": "CameraView",
"audience": "tenant-external",
"description": "View camera streams and metadata."
},
{
"name": "FrameAnalyze",
"audience": "tenant-external",
"description": "Submit frames for analysis."
}
],
"managed_policies": [
{
"name": "AcmeVisionReadOnlyAccess",
"description": "Read camera streams and analysis results.",
"statements": [
{
"Sid": "ReadCameraStreams",
"Effect": "Allow",
"Action": ["acme-vision:CameraView"],
"Resource": ["frn:${account_id}:acme-vision:camera/*"]
}
]
},
{
"name": "AcmeVisionOperatorAccess",
"description": "Use Acme Vision analysis features.",
"statements": [
{
"Sid": "AnalyzeFrames",
"Effect": "Allow",
"Action": ["acme-vision:FrameAnalyze"],
"Resource": ["frn:${account_id}:acme-vision:frame/*"]
}
]
}
],
"managed_permission_sets": [
{
"name": "AcmeVisionViewer",
"policy_names": ["AcmeVisionReadOnlyAccess"]
},
{
"name": "AcmeVisionOperator",
"policy_names": ["AcmeVisionOperatorAccess"]
}
]
},
"quota": {
"catalog": [
{
"key": "camera-streams",
"display_name": "Camera streams",
"unit": "streams",
"scope": "account",
"minimum_value": 0,
"default_value": 50,
"maximum_value": 1000,
"adjustment": {
"mode": "reviewed",
"step": 10,
"apply_endpoint": {
"path": "/api/v1/quotas/camera-streams",
"audience": "acme-vision"
},
"read_endpoint": {
"path": "/api/v1/quotas/camera-streams",
"audience": "acme-vision"
}
}
},
{
"key": "frame-analysis-per-minute",
"display_name": "Frame analysis requests per minute",
"unit": "requests/minute",
"scope": "account",
"minimum_value": 0,
"default_value": 120,
"maximum_value": 10000,
"adjustment": {
"mode": "automatic",
"step": 100,
"apply_endpoint": {
"path": "/api/v1/quotas/frame-analysis-per-minute",
"audience": "acme-vision"
},
"read_endpoint": {
"path": "/api/v1/quotas/frame-analysis-per-minute",
"audience": "acme-vision"
}
}
}
]
},
"audit": {
"events": [
{
"name": "acme-vision.CameraLinked",
"category": "management",
"severity": "medium",
"payload_schema_ref": "https://schemas.acme.example/audit/camera-linked.v1.json"
},
{
"name": "acme-vision.FrameAnalyzed",
"category": "data",
"severity": "low",
"payload_schema_ref": "https://schemas.acme.example/audit/frame-analyzed.v1.json"
}
]
},
"app_launch": {
"launch_path": "/passport/apps/acme-vision",
"required_action": "acmeVision:CameraView",
"resource_frn_pattern": "frn:${account_id}:acme-vision:camera/*",
"allowed_redirect_paths": [
"/passport/apps/acme-vision",
"/partners/acme-vision/dashboard"
],
"installed_accounts": []
},
"backend_metadata": {
"openapi_url": "https://api.acme.example/openapi.json",
"health_url": "https://api.acme.example/health",
"webhook_url": "https://api.acme.example/flexgalaxy/webhooks",
"support_url": "https://acme.example/support",
"data_classification": "tenant-confidential"
}
}
}
The OIDC client is not declared in surfaces.oidc: when omitted, DotID
synthesizes it from your serviceId — client_id = service_id, confidential
by default, realm idc — and validates the synthesized manifest against the
service-registration schema. To control the client explicitly, declare an
oidc surface (client_id, display_name, optional audiences).
命名规则¶
为机器标识符使用稳定的小写 ID:
字段 |
示例 |
规则 |
|---|---|---|
|
|
小写 slug,在 catalog 中全局唯一。 |
|
|
Derived from the service ID; no tenant/account suffix supplied by developer. |
IAM namespace |
|
The service ID is the action namespace. |
IAM action |
|
CamelCase domain action; policy statements reference |
审计事件 |
|
service namespace 加事件名称。 |
配额键 |
|
由 DotID 限定在 service ID 下的稳定 slug。 |
平台负责 tenant-specific suffixing、realm placement、生成的 client ID、installation ID 以及已预配的 resource identifier。
演练¶
设置 base URL:
export FGAI_API_BASE=http://api.dev.fgai.test
export DEVELOPER_TOKEN="<developer bearer token>"
For production, point FGAI_API_BASE at https://api.flexgalaxy.ai instead.
1. Create a service registration¶
curl -fsS \
-X POST "$FGAI_API_BASE/developer/v1/services" \
-H "Authorization: Bearer $DEVELOPER_TOKEN" \
-H "Content-Type: application/json" \
-d @acme-vision.service.json
预期响应:
{
"service_id": "acme-vision",
"version": "1.0.0",
"state": "DRAFT",
"manifest_id": "0a8f4c2e-9d31-4b7a-8e5f-1c2b3a4d5e6f",
"links": {
"self": "/developer/v1/services/acme-vision",
"review": "/developer/v1/services/acme-vision/review",
"catalog": "/service-catalog/v1/services/acme-vision"
}
}
The create call submits the registration for platform review: the manifest
stays a draft and the review state becomes in_review. Check it through the
review link:
curl -fsS \
"$FGAI_API_BASE/developer/v1/services/acme-vision/review" \
-H "Authorization: Bearer $DEVELOPER_TOKEN"
{
"service_id": "acme-vision",
"version": "1.0.0",
"state": "DRAFT",
"manifest_id": "0a8f4c2e-9d31-4b7a-8e5f-1c2b3a4d5e6f",
"review_status": "in_review",
"review_notes": []
}
2. Platform review decision¶
Resubmitting the same version while it is in review is refused — the submitted revision is immutable:
curl -sS \
-X POST "$FGAI_API_BASE/developer/v1/services/acme-vision/submit" \
-H "Authorization: Bearer $DEVELOPER_TOKEN" \
-H "Content-Type: application/json" \
-d @acme-vision.service.json
The API returns 409 Conflict (already submitted).
The review outcome is decided by a platform reviewer on the platform review
surface, not by the developer. There is no partner-facing endpoint for the
decision; the developer observes it through GET /service-catalog/v1/services/{serviceId}
and GET /developer/v1/services/{serviceId}/review.
An approved registration is provisioned and becomes ACTIVE; a REJECTED
decision ends it as FAILED. After approval the review state reads
published:
curl -fsS \
"$FGAI_API_BASE/developer/v1/services/acme-vision/review" \
-H "Authorization: Bearer $DEVELOPER_TOKEN"
{
"service_id": "acme-vision",
"version": "1.0.0",
"state": "ACTIVE",
"manifest_id": "0a8f4c2e-9d31-4b7a-8e5f-1c2b3a4d5e6f",
"review_status": "published",
"review_notes": []
}
The registration is now in the catalog and installable by tenants.
3. Retire a service registration¶
移除所有租户安装后,开发者可以退役该 service registration,使其从公共 catalog 中移除:
curl -fsS \
-X DELETE "$FGAI_API_BASE/developer/v1/services/acme-vision" \
-H "Authorization: Bearer $DEVELOPER_TOKEN"
预期响应:
{
"service_id": "acme-vision",
"version": "1.0.0",
"state": "RETIRED",
"manifest_id": "0a8f4c2e-9d31-4b7a-8e5f-1c2b3a4d5e6f"
}
如果仍存在活跃安装,API 会返回 409 Conflict。请先通过 DELETE /service-catalog/v1/installations/{installation_id} 移除安装。
4. Tenant installs the service¶
当已发布版本在 catalog 中可用后,Account 管理员会查看该条目:
curl -fsS \
"$FGAI_API_BASE/service-catalog/v1/services/acme-vision" \
-H "Authorization: Bearer $ACCOUNT_ADMIN_TOKEN"
The response shows the catalog entry — display name, description, declared actions, quotas, and audit events — with links for review and installation.
安装到 Account:
curl -fsS \
-X POST "$FGAI_API_BASE/accounts/v1/$ACCOUNT_ID/service-installations" \
-H "Authorization: Bearer $ACCOUNT_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"service_id": "acme-vision"
}'
预期响应:
{
"installation_id": "svcinst_01jz0acmevision",
"scope_type": "ACCOUNT",
"scope_id": "acc_01jz0example",
"service_id": "acme-vision",
"version": "1.0.0",
"status": "ACTIVE",
"idempotent": false
}
轮询状态:
curl -fsS \
"$FGAI_API_BASE/service-catalog/v1/installations/svcinst_01jz0acmevision" \
-H "Authorization: Bearer $ACCOUNT_ADMIN_TOKEN"
完成:
{
"installation_id": "svcinst_01jz0acmevision",
"scope_type": "ACCOUNT",
"scope_id": "acc_01jz0example",
"service_id": "acme-vision",
"version": "1.0.0",
"status": "ACTIVE",
"idempotent": false
}
5. Create a PassPort launch link¶
安装后,用户可以通过 PassPort 进入 Acme Vision。
当前 PassPort 运行时端点:
curl -fsS \
-X POST "$FGAI_API_BASE/passport/v1/launch-links" \
-H "Authorization: Bearer $ACCOUNT_ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"appId": "acme-vision",
"accountId": "'"$ACCOUNT_ID"'",
"redirectUrl": "https://app.acme.example/",
"scopes": ["openid"],
"ttlSeconds": 900
}'
预期响应:
The launch URL is issued by PassPort, for example under https://passport.flexgalaxy.ai in production.
{
"appId": "acme-vision",
"accountId": "acc_01jz0example",
"launchToken": "lt_01jz0example",
"launchUrl": "<passport-launch-url>",
"redirectUrl": "https://app.acme.example/",
"scopes": ["openid"],
"expiresAt": "2026-06-07T12:15:00Z"
}
6. Redeem launch and redirect to application¶
浏览器访问 PassPort launch URL。PassPort 会在需要时认证用户,验证安装和 scope,然后签发绑定到应用的 launch ticket,并且只重定向到 allowlist 中的 Acme Vision URL。
概念性重定向:
https://app.acme.example/?launch_ticket=ticket_opaque
launch ticket 生命周期很短,并且绑定到应用。它不是宽泛的控制台会话。
7. Application validates launch ticket¶
Acme Vision 在创建应用会话前验证 launch ticket:
curl -fsS \
-X POST "$FGAI_API_BASE/passport/v1/launch-tickets/validate" \
-H "Content-Type: application/json" \
-d '{
"appId": "acme-vision",
"launchTicket": "ticket_opaque"
}'
预期响应:
{
"valid": true,
"appId": "acme-vision",
"accountId": "acc_01jz0example",
"displayName": "Acme Vision",
"subject": "user_01jz0example",
"redirectUrl": "https://app.acme.example/",
"scopes": ["openid"],
"expiresAt": "2026-06-07T12:16:00Z"
}
如果出现以下情况,应用必须拒绝请求:
valid为 false;appIddoes not match its own app ID;缺少必需的 scope;
ticket 已过期;
the account context is not acceptable for the app session.
安全规则¶
不直接变更 Keycloak¶
第三方开发者不得获得 Keycloak Admin 凭证。
平台负责:
realm placement;
需要 tenant-specific suffixing 时生成的 client ID;
redirect URI 验证;
protocol mapper;
client scope;
tenant-scoped provisioning;
禁用和清理。
OIDC client types¶
The example above registers a confidential client: DotID derives the OIDC
client (client_id = acme-vision) from the request envelope and issues a
client_secret (token_endpoint_auth_method: client_secret_basic). A browser or
native app can instead request a public client with public_client: true —
PKCE (S256) and no client_secret. Native (custom-scheme) and loopback
redirects likewise require a public client; a confidential client that declares
one is rejected 400, never silently downgraded to a secret-bearing client.
Public clients are stamped with the aud (flexgalaxy-api) and account_id
mappers automatically. See
OIDC client setup for the full client-type and
redirect-trust model.
HTTPS redirect URL¶
生产注册必须使用 HTTPS redirect URLs。本地 .test hostnames 仅允许用于本地仿真 fixtures。public client 上的生产 https:// redirect 只有在其 host 通过应用的 verified domains(App Links / Universal Links)证明后才可信 — 参见 Redirect URIs。
生产环境 origin 不允许使用通配符¶
不要批准如下宽泛的重定向模式:
https://*.example.com/*
优先使用精确的 origin 和精确的 callback path:
https://app.acme.example/passport/callback
App-scoped PassPort 会话¶
PassPort 入口不得授予普通控制台访问权限。
应用只能接收绑定到应用的 launch ticket 或 app-scoped token。由此生成的应用会话不得被控制台应用接受。
Scope 交集¶
有效 launch scope 是以下各项的交集:
应用注册的 scope;
平台审核批准的 scope;
租户安装授予的 scope;
launch link 请求的 scope;
认证用户允许使用的 scope。
如果任何一层移除了某个 scope,应用就不会收到该 scope。
幂等性¶
注册和安装 API 应支持 idempotency key。
推荐 header:
Idempotency-Key: acme-vision-1.0.0-submit
使用相同 key 和相同 body 的重复请求应返回现有结果。使用相同 key 但不同 body 的重复请求应返回冲突。
错误模型¶
使用结构化错误:
{
"error_code": "redirect_uri_not_allowed",
"message": "Redirect URI is not registered for this application.",
"details": {
"field": "surfaces.oidc.redirect_uris[1]"
}
}
推荐的 HTTP 状态码:
状态码 |
含义 |
|---|---|
|
schema validation 之外的语法级请求错误。 |
|
缺少 bearer token 或 bearer token 无效。 |
|
已认证的参与者缺少权限。 |
|
未找到 registration、service、installation 或 app。 |
|
idempotency、version 或 namespace 冲突。 |
|
manifest schema 或语义验证失败。 |
|
超过速率限制。 |
非目标¶
本示例不涵盖:
直接使用 Keycloak Admin API;
普通控制台登录;
StartPoint account 选择;
platform-admin UI 实现;
生产计费或商业条款。