secrets
它能做什么
这项技能说明应用应如何保存和使用凭据,例如 API 密钥和 OAuth 连接。适合添加需要用户或工作区的登录或密钥的功能的开发者。
适用场景
- ✓当某项功能需要 API 密钥或外部服务登录的时候。
- ✓当你添加 OAuth,让用户可以连接自己的账户的时候。
- ✓当你想把密钥粘贴到源代码或普通设置值中的时候。
技能链接
https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/secrets/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请添加一个需要 API 密钥的功能,并确保密钥被安全存储,而不是写在代码中。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体先检查是否已有现有连接,然后使用共享的 OAuth 流程或共享的机密系统。密钥绝不放入应用代码或客户端可见的状态中。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Secrets
Rule
Credentials belong to the user, organization, workspace, or deployment that owns them. Reuse the strongest shared connection or credential flow available; never copy a value into app code or client-visible state.
Choose the credential source
- Check the workspace connection catalog first. If the provider is already connected, request the app grant and resolve its vault-backed credential reference through the workspace-connection API.
- For OAuth, use the shared authorization and token flow. Do not store access or refresh tokens as ordinary settings or API-key values.
- If the app truly needs its own API key, register it with the shared secrets surface. Do not build a parallel key form or storage table.
- Use deployment configuration only for a secret owned by the deployed app, such as a webhook verification secret. LLM inference keys are an app-owned exception: self-hosted apps may use provider keys from deployment env as a shared fallback, while scoped user or organization keys take precedence. Hosted-workspace deployments backed by a shared database must not share those env keys across apps or tenants. This exception does not authorize using env credentials to access user-owned provider data.
Register an app-local API key
Register the key once so Settings can manage it and the app can describe why it
is needed. Supported scopes are user, org, and workspace; choose the
narrowest scope that matches who owns the credential and how the app resolves
it. Put the registration in a server module imported by a loaded server plugin.
import { registerRequiredSecret } from "@agent-native/core/secrets";
registerRequiredSecret({
key: "EXAMPLE_SERVICE_API_KEY",
label: "Example service API key",
description: "Connects this app to the example service.",
docsUrl: "https://example.com/api-keys",
scope: "user",
kind: "api-key",
required: true,
});
Use kind: "oauth" for an OAuth-backed connection and set oauthProvider and
oauthConnectUrl for the shared Connect flow. Set required only when the app
cannot perform its primary workflow without that connection. A validator may
check a key before save; never log or include the value in a validation error.
Resolve credentials on the server
Resolve credentials only inside server-side actions or server helpers, using the request's user and organization context. Keep a missing key separate from a failed credential-store lookup: ask the user to connect the provider only when the credential is absent; make a store failure retryable.
For an app-local key, use resolveSecretDetailed() from
@agent-native/core/server in the request context. Check lookupFailed before
checking value; do not turn a failed lookup into a setup prompt.
Never read a user's or workspace's API key from process.env, or add a raw
environment fallback to a scoped lookup. Do not put credentials in action
arguments or results, agent messages or hidden context, application state,
browser storage, client bundles, logs, or error text. Send them only in the
provider request that needs them, and redact provider responses before
returning an error.
Related skills
security— protect access to app data and external requests.actions— expose server-side operations to both the agent and UI.
常见问题
密钥可以保存为普通设置吗?
不可以。访问令牌和刷新令牌不得保存为普通设置或 API 密钥值。
什么时候允许使用环境变量?
只用于部署级别的值,例如 webhook 验证密钥。
如果服务商已经连接了怎么办?
应用会使用现有连接,而不是再次要求用户输入密钥。
详情
作者的原始描述
Connect external services and keep app credentials scoped. Use before adding an API key, OAuth connection, provider setup, or server-side request that needs a user's or workspace's credential.
repo: BuilderIO/agent-native
热度
- GitHub 星标
- 7.6k
- 排名
- #13179
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …