跳到正文

标准 · 委托

委托与 CIBA

三项标准供代表个人行动的应用与代理使用:令牌交换(RFC 8693)把更窄的令牌交给另一服务或代理,富授权请求(RFC 9396)请求具体事项而非宽泛范围,以及 CIBA(OpenID Connect Client-Initiated Backchannel Authentication)请对方在自有设备上批准。

每项功能按环境可选:在开发者控制台打开应用,选择环境并使用 Delegation 卡片。仅机密(服务端)环境可用。本 Identvia 服务器的运营商可关闭各项功能;https://id.identvia.com/.well-known/openid-configuration 的发现始终说明哪些已开启。

令牌交换(RFC 8693)

用你持有的访问令牌换取新的、更短寿、更窄且可选指名代表对方行动的代理的令牌。

HTTP
POST /oauth/token
Authorization: Basic base64(client_id:client_secret)
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&subject_token=<access token issued to you>
&subject_token_type=urn:ietf:params:oauth:token-type:access_token
&audience=<another Identvia client_id, or the MCP resource>
&scope=openid email
&actor_token=<agent JWT, optional>
&actor_token_type=urn:ietf:params:oauth:token-type:jwt

规则

  • subject 令牌必须是颁发给你的 Identvia 访问令牌,或其 aud 点名你。对方与原应用的连接须仍有效。
  • 范围只能缩小。未发送 scope 时,得到原始范围减去 offline_access。offline_access 永不交换,也不签发 refresh 或 ID 令牌。
  • audience(或 resource)必须是活跃的 Identvia 客户端或 Identvia MCP 资源。其他情况返回 invalid_target。当 audience 是另一客户端时,sub 是该人对该客户端的 pairwise 标识符。
  • 新令牌最长存活 10 分钟,且不超过来源令牌。链路限于 3 跳。
  • 撤销原始令牌,或对方断开应用,会立即关闭所有派生令牌(内省返回 active: false)。
  • 无效的 subject 或 actor 令牌返回 invalid_request,符合 RFC 8693 §2.2.2。

Actor 令牌

要指名代理,发送 actor 令牌:由对方在账户 Agents 下注册的代理密钥签名(ES256 或 RS256)的 JWT。

JSON
header:  { "alg": "ES256", "kid": "<RFC 7638 JWK thumbprint of the agent key>" }
payload: { "sub": "<harness id shown in the person's Agents page>",
           "aud": "https://id.identvia.com",
           "iat": 1700000000, "exp": 1700000120,
           "jti": "<unique, single use>" }

令牌须在 5 分钟内过期,每个 jti 只用一次,被封禁的代理会被拒绝。签发的令牌带标准 act 声明;更早的 actor 嵌套其中:

JSON
{ "sub": "…", "aud": "oid_…", "scope": "openid email",
  "act": { "sub": "harness-123", "agent_tier": "registered",
           "act": { "sub": "oid_first_app" } } }

按 RFC 8693 §4.1,访问决策应基于顶层声明且仅基于当前 actor;嵌套 actor 只是历史。

富授权请求(RFC 9396)

在授权请求中发送 authorization_details(JSON 数组)。本服务器接受的类型:agent_task。

JSON
[{ "type": "agent_task",
   "actions": ["read", "summarize"],
   "locations": ["https://api.example.com/inbox"],
   "datatypes": ["messages"],
   "identifier": "folder-42" }]
  • 即使对方以前信任你的应用,同意屏幕上仍会看到具体请求。
  • 通用字段 locations、actions、datatypes 和 privileges 必须是字符串数组;identifier 必须是字符串。最多 10 条、4 KB。
  • 已授予的详情出现在令牌响应、访问令牌的 authorization_details 声明、内省以及刷新之后。
  • 错误使用 invalid_authorization_details。
  • 令牌交换继承详情,或可以收窄;不能扩大或新增。

CIBA:在本人设备上批准

适用于呼叫中心、自助亭或知道对方是谁但没有浏览器会话的后台代理。在 Delegation 卡片中选择 Poll 或 Ping。

HTTP
POST /oauth/bc-authorize
Authorization: Basic base64(client_id:client_secret)

scope=openid email
&login_hint=person@example.com
&binding_message=Desk 4 · code 7Q2K
&requested_expiry=120

→ 200 { "auth_req_id": "…", "expires_in": 120, "interval": 5 }
  • login_hint 必须是电子邮箱。id_token_hint、login_hint_token、签名请求(request)和 user_code 不受支持,返回 invalid_request。
  • 无论邮箱是否属于某人,响应看起来相同,因此不能用来查找账户。未知用户只会永不批准。
  • 在你的屏幕上显示同一个 binding_message;对方会在 Identvia 收件箱和邮件中看到它,并标明是来自你的应用的消息,然后确认两者一致。最多 48 个字符:字母、数字、空格和基本标点(- _ . , : # ( ) · !)。链接、域名和电子邮件地址会以 invalid_binding_message 被拒绝。每个人每小时从所有应用总共最多只会收到少量请求。
  • 对方收到指向收件箱的邮件链接,绝不是批准链接。批准需要新的通行密钥或身份验证器应用核验。

Poll 模式

HTTP
POST /oauth/token
grant_type=urn:openid:params:grant-type:ciba&auth_req_id=…

→ 400 authorization_pending | slow_down | access_denied | expired_token
→ 200 { "access_token": "…", "id_token": "…", "refresh_token": "…" }

轮询间隔至少 interval 秒。过快返回 slow_down 并给间隔加 5 秒。auth_req_id 只能兑换一次。

Ping 模式

在应用自有域名注册 https 通知端点,并在每次请求中发送 client_notification_token。当对方决定时,Identvia 向该端点 POST {"auth_req_id": "…"},带 Authorization: Bearer <your client_notification_token>。校验令牌,返回 204,再按 poll 模式调用令牌端点。不提供 push 模式。

PHP SDK

PHP
// 令牌交换:给另一应用更窄的令牌,可选指名代理
$t = $identvia->tokenExchange($accessToken, audience: 'oid_other_app', scope: 'openid email', actorToken: $agentJwt);
$t->accessToken;              // 无 refresh 令牌,短寿

// CIBA(poll)
$req = $identvia->cibaAuthorize('person@example.com', scope: 'email', bindingMessage: 'Desk 4 · 7Q2K');
$interval = $req['interval'];
while (($tokens = $identvia->cibaPoll($req['auth_req_id'], $interval)) === null) { sleep($interval); }
// throws TokenException with error access_denied or expired_token when it's over

// CIBA(ping):在你的通知端点
$id = Identvia\Sdk\Identvia::verifyCibaPing($_SERVER['HTTP_AUTHORIZATION'] ?? '', file_get_contents('php://input'), $storedToken);

// 登录时的富授权请求
$identvia->redirectToSignIn(['authorization_details' => [['type' => 'agent_task', 'actions' => ['read']]]]);

发现

启用时,发现列出 urn:ietf:params:oauth:grant-type:token-exchange 与 urn:openid:params:grant-type:ciba 于 grant_types_supported,以及 authorization_details_types_supported、backchannel_authentication_endpoint、backchannel_token_delivery_modes_supported 和 backchannel_user_code_parameter_supported: false。

我们遵循哪些 IETF 代理身份草案及严格程度,见下载中的 docs/standards.md。