Auth0 AI Agent 身份验证方案上线
Auth0 推出专为 AI Agent 设计的身份认证服务,简化 Agent 应用的安全管理,对 Agent 开发者有实用价值。
Auth0 推出专为 AI Agent 设计的身份认证服务,简化 Agent 应用的安全管理,对 Agent 开发者有实用价值。
TL;DR:Auth0 for AI Agents 现已正式发布!更安全地连接 AI 智能体与应用和数据,让用户控制 AI 智能体可以执行的操作和访问的数据,并为关键智能体操作启用人工确认。立即开始构建。
随着团队加快构建 AI 智能体的步伐,在速度和精确性之间取得平衡至关重要。目前,最快速上手的方式是使用 AI 智能体框架,让 AI 智能体使用硬编码的凭证或 API 密钥。采用这种方式时,你会发现这仅适用于开发和测试,不适合将 AI 智能体部署到生产环境。这种方法存在缺陷,因为它不仅给予 AI 智能体超出必要的访问权限,还缺乏实现强大安全性所需的基本身份验证方案。这在框架范围之外留下了大量未解决的漏洞:
你的 AI 智能体如何识别用户并安全地连接到他们的应用和 API?
你如何维持智能体的监督权并为关键操作构建人工批准机制?
如果未能妥善解决这些挑战并设置特定的智能体访问参数来主动保护用户数据,可能会迅速将你的 AI 智能体变成重大风险。
Auth0 for AI Agents 为开发者提供了一个安全的基础,使其能够在不损害安全性或创新的前提下构建 AI 智能体。这个完整的解决方案安全地连接你的 AI 智能体与应用和数据,在每个场景中应用正确的用户权限。如果你正在构建 AI 智能体,我们允许你:
识别与智能体交互的用户。
给予 AI 智能体访问你拥有的用户数据的权限。例如,他们的聊天历史记录、偏好设置或之前的订单。
例如,他们的聊天历史记录、偏好设置或之前的订单。
以该用户的名义更安全地连接应用。例如,检查他们的日历并安排预约、发送电子邮件或预订机票。
例如,检查他们的日历并安排预约、发送电子邮件或预订机票。
让你的用户在智能体工作流中的适当时刻控制并批准关键操作,例如发送文档或允许购买。
通过为 AI 智能体设置特定的访问参数,基于用户权限强制执行细粒度数据访问控制,以更好地保护用户数据。
Auth0 for AI Agents 包括四个功能,可用于 B2B、B2C 和内部应用:用户身份验证、Token Vault、异步授权和 FGA for RAG。
更安全且可扩展的用户身份验证可以启用安全性、保护数据、控制功能访问,同时为你的智能体提供对第一方 API 的安全访问。一个示例用例是与客户合作的客服 AI 智能体。用户登录后,用户身份验证可以让智能体识别用户及其订单历史记录。
@router.get("/protected")
def protected_route(auth_session=Depends(auth0_client.require_session)):
user = auth_session.get("user")
if not user:
return {"error": "User not authenticated"}
return {
"message": f"Hello {user.get('email')}!",
"user_id": user.get("sub")
}
export default async function Home() {
const session = await auth0.getSession();
if (!session) {
return (
<main>
<a href="/auth/login?screen_hint=signup">Sign up</a>
<a href="/auth/login">Log in</a>
</main>
);
}
return (
<main>Welcome, {session.user.name}!</main>
);
}
Token Vault 是一个安全的集中式授权层,将你的 AI 智能体与第三方 API 和外部系统(如 Google Drive、Jira 或 Slack)集成。Auth0 通过自动存储、管理和刷新 OAuth token,帮助保护对这些外部系统的凭证,确保敏感数据和凭证永远不会有风险或存储在你的智能体逻辑中。同时,你可以控制哪些智能体可以访问哪些第三方系统。Token Vault 允许 AI 智能体无缝地代表最终用户行动,最终用户仅需提供一次同意,这使其成为连接集成应用和任何 OAuth 服务的安全且简单的解决方案。
一个示例内部用例是构建需要访问 GitHub 和 Slack 的生产力 AI 智能体。赋予你的 AI 智能体能力以通过 35+ 个支持的应用集成进行操作,并通过标准 OAuth 支持连接到任何其他应用。
with_slack_connection = auth0_ai.with_token_vault(
connection="sign-in-with-slack",
scopes=["channels:read"],
)
@tool
def list_channels_tool_function(date: datetime):
# Get the access token from Auth0 AI
access_token = get_access_token_from_token_vault()
# Call Slack SDK
client = WebClient(token=access_token)
response = client.conversations_list(
exclude_archived=True,
types="public_channel,private_channel",
limit=10
)
channels = response['channels']
channel_names = [channel['name'] for channel in channels]
return channel_names
list_slack_channels_tool = with_slack_connection(StructuredTool(
name="list_slack_channels",
description="List channels for the current user on Slack",
args_schema=EmptySchema,
func=list_channels_tool_function,
))
export const withSlackConnection = auth0AI.withTokenVault({
connection: 'sign-in-with-slack',
scopes: ['channels:read'],
});
export const listChannels = withSlackConnection(
tool({
description: "List channels for the current user on Slack",
parameters: z.object({}),
execute: async () => {
// Get the access token from Auth0 AI
const accessToken = getAccessTokenFromTokenVault();
// Call Slack SDK
const web = new WebClient(accessToken);
const result = await web.conversations.list({
exclude_archived: true,
types: "public_channel,private_channel",
limit: 10,
});
return result.channels?.map((channel) => channel.name);
},
})
);
Auth0 for AI Agents 让 AI 智能体能够使用客户端发起的后通道身份验证流 (CIBA) 异步授权用户。AI 智能体可以在后台工作,仅在需要进行关键操作时通知用户。
当你为 AI 智能体工作流添加更安全的人工审批循环时,可以使用 Auth0 请求用户权限来完成授权请求。AI 智能体可以在同意提示中呈现丰富的授权数据,让用户清楚地了解他们授权的内容。
一个示例用例是用户请求你的 AI 智能体进行在线购买,但智能体需要确认才能完成交易。即使 AI 智能体想购买产品,它也没有权限自行购买,因为它没有用户授权。只有当用户批准交易时,我们才向智能体颁发代表用户执行操作的令牌。这意味着你的用户保持完全控制。
with_async_user_confirmation = auth0_ai.with_async_authorization(
audience=settings.SHOP_API_AUDIENCE,
binding_message=lambda product: f"Do you want to buy {product}",
user_id=get_user_id(config),
)
@tool
async def shop_online_fn(product: str):
"""Tool to buy products online."""
credentials = get_async_authorization_credentials()
async with httpx.AsyncClient() as client:
response = await client.post(
API_URL,
headers={
"Authorization": f"Bearer {credentials['access_token']}",
},
json={ "product": product },
)
return response.json()
with_async_user_confirmation = auth0_ai.with_async_authorization(
audience=settings.SHOP_API_AUDIENCE,
binding_message=lambda product: f"Do you want to buy {product}",
user_id=get_user_id(config),
)
@tool
async def shop_online_fn(product: str):
"""Tool to buy products online."""
credentials = get_async_authorization_credentials()
async with httpx.AsyncClient() as client:
response = await client.post(
API_URL,
headers={
"Authorization": f"Bearer {credentials['access_token']}",
},
json={ "product": product },
)
return response.json()
export const withAsyncAuthorization = auth0AI.withAsyncAuthorization({
userID: async () => await getUser(),
bindingMessage: async ({ product }) => `Do you want to buy ${product}`,
audience: process.env['API_AUDIENCE']!,
});
export const shopOnlineTool = withAsyncAuthorization(tool({
description: 'Tool to buy products online',
parameters: z.object({ product: z.string() }),
execute: async (params) => {
const credentials = getAsyncAuthorizationCredentials();
const response = await fetch(API_URL, {
headers: {
Authorization: `Bearer ${credentials?.accessToken}`,
},
body: JSON.stringify(params),
});
const result = await response.json();
return result;
},
}));
export const withAsyncAuthorization = auth0AI.withAsyncAuthorization({
userID: async () => await getUser(),
bindingMessage: async ({ product }) => `Do you want to buy ${product}`,
audience: process.env['API_AUDIENCE']!,
});
export const shopOnlineTool = withAsyncAuthorization(tool({
description: 'Tool to buy products online',
parameters: z.object({ product: z.string() }),
execute: async (params) => {
const credentials = getAsyncAuthorizationCredentials();
const response = await fetch(API_URL, {
headers: {
Authorization: `Bearer ${credentials?.accessToken}`,
},
body: JSON.stringify(params),
});
const result = await response.json();
return result;
},
}));
Guardian 的推送通知现已可用。电子邮件和短信渠道即将推出。
Auth0 for AI Agents 使 AI 智能体能够为检索增强生成(RAG)实现细粒度授权,也称为 FGA for RAG。当 AI 智能体使用 RAG 为用户查询提供复杂而相关的响应时,它们只能访问授权的数据。
一个示例是 GTM 销售 AI 智能体搜索公司文档以获取竞争对手情报和推销分析。AI 智能体快速搜索所有文档并为你的销售团队提供直接、即时的答案。虽然这是一个很好的能力,但你需要确保用户只收到他们有权访问的文档中的答案,而不是所有公司文档。看看代码的底层逻辑:
细粒度授权使你能够建模复杂的权限结构,例如涉及文档访问的权限结构,其中用户有各种权限级别(查看、评论、编辑或分享)。此外,用户可以属于多个组,从中继承权限。细粒度授权在具有大量文档的复杂权限情况下具有可伸缩性和高性能。在知识助手型 AI 智能体中使用 FGA for RAG 作为安全层,以在搜索期间强制执行文档权限。
@tool
def get_context_documents_tool(query: str):
"""Use the tool when user asks for documents"""
retriever = FGARetriever(
retriever=vector_store.as_retriever(),
build_query=lambda doc: ClientBatchCheckItem(
user=f"user:{user_email}",
object=f"doc:{doc.metadata.get('documentId')}",
relation="can_view",
),
)
documents = retriever.invoke(query)
return "\n\n".join([document.page_content for document in documents])
@tool
def get_context_documents_tool(query: str):
"""Use the tool when user asks for documents"""
retriever = FGARetriever(
retriever=vector_store.as_retriever(),
build_query=lambda doc: ClientBatchCheckItem(
user=f"user:{user_email}",
object=f"doc:{doc.metadata.get('documentId')}",
relation="can_view",
),
)
documents = retriever.invoke(query)
return "\n\n".join([document.page_content for document in documents])
export const getContextDocumentsTool = tool(
async ({ question }) => {
const user = await auth0.getUser();
const retriever = FGARetriever.create({
retriever: vectorStore.asRetriever(),
buildQuery: (doc) => ({
user: `user:${user?.email}`,
object: `doc:${doc.metadata.documentId}`,
relation: 'can_view',
}),
});
const documents = await retriever.invoke(question);
return documents.map((doc) => doc.pageContent).join('\n\n');
},
{
name: 'get_context_documents',
description: 'Use the tool when user asks for documents',
schema: z.object({ question: z.string() }),
},
);
export const getContextDocumentsTool = tool(
async ({ question }) => {
const user = await auth0.getUser();
const retriever = FGARetriever.create({
retriever: vectorStore.asRetriever(),
buildQuery: (doc) => ({
user: `user:${user?.email}`,
object: `doc:${doc.metadata.documentId}`,
relation: 'can_view',
}),
});
const documents = await retriever.invoke(question);
return documents.map((doc) => doc.pageContent).join('\n\n');
},
{
name: 'get_context_documents',
description: 'Use the tool when user asks for documents',
schema: z.object({ question: z.string() }),
},
);
这些 SDK 使你能够快速轻松地使用 LangChain、LlamaIndex 和 Cloudflare Agents 等框架将 Auth0 与你的 AI 智能体集成。
我们的 SDK 检测工具调用何时需要用户进行身份验证,并将中断工具调用流,显示消息告诉用户需要进行身份验证。用户进行身份验证后,工具调用会自动恢复。SDK 使用 Auth0 的 Token Vault,该 Vault 存储用户对外部 API 的访问令牌。这意味着在后续工具调用中,用户无需再次进行身份验证,因为 Token Vault 将自动提供访问令牌。
查看 Assistant0:一个使用 Auth0 保护的 AI 个人助手。它是一个 AI 个人助手,通过动态访问多个工具来整合你的数字生活,帮助你保持有条不紊和高效。
LangChain + JavaScript
LlamaIndex + JavaScript
Vercel AI + JavaScript
Auth0 AI for LangChain:Auth0 for AI Agents、LangChain 和 LangGraph SDK 使你能够轻松地使用 LangChain 和 LangGraph 集成和保护 AI 智能体工作流。开始使用 >>
npm install @auth0/ai-langchain
npm install @auth0/ai-langchain
pip install auth0-ai-langchain
pip install auth0-ai-langchain
Auth0 AI for LlamaIndex:Auth0 for AI Agents 和 LlamaIndex SDK 让你能够轻松集成并保护使用 LlamaIndex 构建的 AI 智能体工作流。立即开始 >>
npm install @auth0/ai-llamaindex
npm install @auth0/ai-llamaindex
pip install auth0-ai-llamaindex
pip install auth0-ai-llamaindex
Auth0 AI for Vercel AI SDK:Auth0 for AI Agents 和 Vercel AI SDK 让你能够轻松集成并保护使用 Vercel AI 构建的 AI 智能体工作流。立即开始 >>
npm install @auth0/ai-vercel
npm install @auth0/ai-vercel
Auth0 即将推出的功能
Auth for MCP 目前处于抢先体验阶段。在此申请加入该计划 >>。Auth for MCP 将允许你在由 MCP 驱动的工作流中使用 Auth0 的功能。在用户或其 AI 智能体连接到 MCP Server 之前对用户进行身份验证;注册 MCP 客户端和服务器,使 AI 智能体能够使用 OAuth 2.0 安全地连接到你的资源;并通过自定义令牌交换安全地连接到你的内部 API。
跨应用访问(Cross App Access,XAA)是一种开放协议,它扩展了 OAuth,通过将授权同意和策略执行转移至身份提供商(Identity Provider,IdP),支持安全的智能体到应用以及应用到应用通信。Auth0 即将原生实现该协议,使你的应用既可作为请求方应用运行(通过交换 ID-JAG 令牌获取访问权限),也可作为资源应用运行(验证并签发限定作用域的令牌)。当你的客户使用支持该协议的参与方 IdP(例如 Okta)时,他们将能够对所有应用和智能体连接进行集中控制、查看和治理。注册参与 Beta 测试。
使用 Auth0 构建强大的 AI 智能体
立即开始构建:
我们的免费方案包含 Token Vault 中的两个已连接应用及更多功能。随着业务规模扩大,我们还提供包含更多升级功能的自助式方案。立即开始构建 >>
现有 Auth0 用户无论当前使用何种 Auth0 方案,都可以免费开始使用。立即开始 >>
我们为符合条件的初创公司提供一年免费的 Auth0。立即申请 >>
我们为符合条件的非营利组织提供自助式方案和企业方案五折优惠。立即申请 >>
有问题?欢迎参加我们于 1 月 14 日举办的社区 AMA,并在此提交你的问题;你也可以参加我们于 12 月 11 日举办的 Reddit AMA。
借助 Auth0 for AI Agents,你可以快速行动、负责任地构建,并始终掌控全局。
Auth0 首席产品官