跳到正文

智能体 · 进行中

面向服务的 AgentPass

让 AI 智能体在用户明确批准下代表你的用户行动,而无需共享密码或会话。Identvia 是 AgentPass v0.1 的 联邦 Authority;你的站点是 Service。

复制给你的 AI 代理用的提示词

在用编程代理?这段提示词会把它指向这些文档,并列出它必须遵守的规则。像审查其他代码一样审查它写的代码。

You are helping me add "Sign in with Identvia" to my app (PHP). Identvia is an OpenID Connect provider.

Read these first (they are plain Markdown and are the source of truth; prefer them over anything you remember):
- https://id.identvia.com/developers/docs/quickstart.md
- https://id.identvia.com/developers/docs/oidc.md
- https://id.identvia.com/developers/docs/security.md
- Discovery: https://id.identvia.com/.well-known/openid-configuration

Stack: plain PHP 8.1+ (no framework). Use the official SDK identvia/identvia-php (composer require identvia/identvia-php, or the zip with vendor/ from https://id.identvia.com/developers/docs/php for hosts without Composer). Create identvia.php (config), login.php (redirectToSignIn), callback.php (handleCallback, then session_regenerate_id(true) and store sub) and logout.php. Read secrets from environment variables or a config file outside the web root.

Requirements:
1. Authorization code flow with PKCE (S256 only), a random state and a nonce per sign-in. No implicit flow.
2. Validate the ID token: RS256 signature from the JWKS, iss = https://id.identvia.com, aud contains my client_id, exp/iat, and the nonce.
3. Identify users by sub (it is pairwise: different for every app). Treat email as optional, because the person may choose not to share it.
4. Redirect URIs must match exactly. Keep the client secret and refresh tokens server-side; never log tokens.
5. Ask only for the scopes I need (openid, plus email/profile if used). Handle the user canceling (error=access_denied) gracefully.

Optional, only if I ask for AI-agent access later:
- AgentPass (agents acting for a user with single-use, holder-bound passes): https://id.identvia.com/developers/docs/agentpass.md
- MCP server for agent clients: https://id.identvia.com/developers/docs/mcp.md
- Token exchange, rich authorization requests and CIBA: https://id.identvia.com/developers/docs/delegation.md

Before writing code, tell me which files you will add or change. Don't invent endpoints or options that aren't in the docs; if something is unclear, ask me.

AgentPass v0.1 是草案规范,可能变更。Identvia 实现钉在 clerk/agentpass@937efe3 的版本。暂勿将不可逆或高价值操作置于其后。

工作原理

  1. 智能体的 harness 向 Identvia 申请通行证:哪个站点、哪个用户、什么任务、哪种类型(bearer_token 或 browser_session)以及 harness 公钥。
  2. Identvia 通过 DNS 找到你的站点,询问有哪些权限,并将请求放入用户收件箱。用户选择权限并用通行密钥或身份验证器应用批准。智能体绝不能批准自己的请求。
  3. Harness 获得通行证:一次有效、仅限你的站点、2 分钟内,且仅配合 harness 密钥签署的证明。
  4. 你的站点兑换通行证:向 Identvia 校验、验证证明,并签发自己的 API 令牌或一次性登录链接。
  5. 智能体工作时,你的站点至少每 60 秒重新检查委托。用户在 Identvia 撤销后,智能体即停止。

PHP:identvia/agentpass-php

在 GitHub 上查看 · 全部 SDK

面向任何 PHP 8.1+ 站点的 MIT 许可库(无框架,可用于共享主机)。提供 AgentPass 端点、DNS 发现与 authority 解析,向 Authority 校验通行证、验证持有者证明、签发 bearer 令牌或浏览器会话,并运行持续检查(失败关闭)。

PHP
$service = new AgentPass\Service\Service(new AgentPass\Service\ServiceConfig(
    origin: 'https://todo.example.com',
    signingKeyPem: file_get_contents(__DIR__ . '/agentpass-key.pem'),   // bin/agentpass-keygen
    trustedAuthorities: [AgentPass\Service\ServiceConfig::authority('https://id.identvia.com')],
    scopes: [['name' => 'todos:read', 'description' => 'See your todos'], ['name' => 'todos:write', 'description' => 'Add todos']],
    store: AgentPass\Service\Store\PdoStore::sqlite(__DIR__ . '/data/agentpass.sqlite'),
));
if ($service->handleGlobals()) { exit; }            // /agentpass-service/* 端点

// 在你的 API 中:
$d = $service->authenticateBearer($_SERVER['HTTP_AUTHORIZATION'] ?? '');
if (!$d->can('todos:write')) { /* 403 */ }

下载包含完整的待办演示服务(examples/todo),接受 bearer 令牌与浏览器会话。

DNS 记录

发布一条 TXT 记录,以便 Authority 找到你的配置:

DNS
_agentpass-service.todo.example.com.  TXT  "https://todo.example.com/agentpass-service/config.json"

企业域名可发布 _agentpass.<domain> 并指向自有 Authority URL,或 none 以禁用委托。Identvia 与 SDK 遵守该优先级。

Identvia 的 Authority 端点

  • 配置:https://id.identvia.com/agentpass/ap
  • 签发:POST /agentpass/requests → 202 带状态链接;轮询间隔不短于 poll_after_ms。
  • Validate 与 authorization-check:由 Service 使用其 JWKS 中密钥签署的短期 ES256 断言调用。

你的责任

  • 将智能体视为代表用户行动,但加以标注:在 UI 与日志中显示「via agent」。
  • 提供窄权限。切勿提供 *;Identvia 也不会。
  • 将 checkCacheSeconds 保持在 60 或更小,无法联系 Authority 时失败关闭。
  • 将任务描述视为来自智能体的不可信文本。