如何在 Gemini Enterprise 自定义 UI 中处理用户、连接器和智能体身份验证
原题How to handle user, connector, and agent auth in Gemini Enterprise with a custom UI
读前速览
本文介绍为 Gemini Enterprise 构建自定义 UI 时,如何实现用户身份、联邦连接器和自定义 ADK 智能体的身份验证,并详述 3 种模式(Google Identity、Workforce Identity Federation、Workload Identity Federation)以及按需触发的工具 OAuth 流程。
StreamAssist API 访问的 3 种身份验证模式
模式 1A 面向 Google Workspace 用户,使用 Google Identity;模式 1B 面向 Entra ID 或 Okta 等外部身份提供方,使用 Workforce Identity Federation;模式 1C 面向非个性化的后端机器人,使用 Workload Identity Federation。每种模式都需要 Discovery Engine User IAM 角色和相应许可。
通过 3LO 流程对联邦连接器进行身份验证
自定义 UI 必须发现连接器、检查 Keystore 中是否存在有效令牌、在需要时触发 3LO 同意弹窗,并将刷新令牌保存到 Keystore。文章还提醒,若使用自定义域名,需要启用由 GE FE Server 自动接管弹窗的功能。
为自定义 ADK 智能体实现按需工具 OAuth
使用由 GCP Auth Manager 的 Token Vault 支持的 GcpAuthProvider 封装受保护的子智能体工具后,StreamAssist 便可仅在调用特定工具时触发 3LO 弹窗,避免一开始就阻塞流程,并支持按工具进行授权。
完整摘要
本文为计划构建 Gemini Enterprise 自定义 UI 的企业提供全面指南,介绍内置 Web 应用会自动处理的 3 种关键身份验证流程。文章详细说明了用于向 StreamAssist 进行身份验证的模式 1A(Google Identity)、模式 1B(Workforce Identity Federation)和模式 1C(Workload Identity Federation)。随后,指南介绍如何通过三方 OAuth(3LO)对联邦连接器进行身份验证,包括发现连接器、检查 Keystore、触发同意弹窗,以及存储刷新令牌。最后,文章说明如何使用 GCP Auth Manager 的 Token Vault,为自定义 ADK 智能体实现按需触发的工具级 OAuth,使各个工具仅在需要时触发身份验证,而不必一开始就阻塞整个智能体。文章还包含架构图,并提供一个 GitHub 代码库,其中有涵盖全部 3 个身份验证层的可运行示例。
目录 · 9 节
使用开箱即用的 Gemini Enterprise Web 应用时,身份与访问管理会在后台自动完成。员工通过 Google Identity 或 Workforce Identity Federation(例如 Microsoft Entra ID 或 Okta)登录;搜索结果会自动遵循每位用户的访问控制列表(ACL);而 Federated Connectors 或自定义代理所需的第三方登录提示,也会自动显示在聊天界面中。When using the out-of-the-box Gemini Enterprise web application, identity and access management happen behind the scenes. Employees sign in through Google Identity or Workforce Identity Federation (such as Microsoft Entra ID or Okta), search results automatically respect per-user access controls (ACLs), and third-party login prompts for Federated Connectors or custom agents appear automatically in the chat UI.
然而在实践中,许多企业会构建自己的 Customer UI,将 Gemini Enterprise 嵌入内部门户、内联网或业务线应用程序。为此,Customer BE 会调用 Gemini Enterprise StreamAssist API。In practice, however, many enterprises build their own Customer UI to embed Gemini Enterprise into an internal portal, intranet, or line-of-business application. To do this, Customer BE calls the Gemini Enterprise StreamAssist API.
一旦应用构建了自定义 UI 并直接调用 StreamAssist API,内置 Web 应用原本会自动处理的三种身份验证流程,就将由 Customer UI 和 Customer BE 负责:The moment an application builds a custom UI and calls the StreamAssist API directly, the three authentication flows that the built-in web app handled automatically become the responsibility of Customer UI and Customer BE:
- 向 StreamAssist 进行身份验证(用户身份与工作负载身份):对于需要考虑文档 ACL、隔离的聊天记录和受限代理权限的面向用户的应用,Customer UI 和 Customer BE 必须通过 Google Identity(模式 1A)或 Workforce Identity Federation(模式 1B)传递已登录员工的身份。对于非个性化的后端机器人或共享服务门户,Customer BE 可以使用 Workload Identity Federation(模式 1C)以无密钥方式进行身份验证。Authenticating to StreamAssist (User Identity vs. Workload Identity): For user-facing applications where document ACLs, isolated chat history, and restricted agent permissions matter, Customer UI and Customer BE must pass the signed-in employee's identity via Google Identity (Pattern 1A) or Workforce Identity Federation (Pattern 1B). For non-personalized backend bots or shared service portals, Customer BE can authenticate keyless using Workload Identity Federation (Pattern 1C).
- 通过客户 UI 对联合连接器进行身份验证:实时联合连接器使用三方 OAuth(3LO),因此只能检索已登录员工有权查看的 Google Drive 文件、SharePoint 站点、Jira 问题或 ServiceNow 事件。由于客户 UI 没有 Gemini Enterprise 内置的“连接”按钮,客户 BE 和客户 UI 必须发现引擎的连接器、检查 Keystore 中是否有有效令牌、在需要时触发 3LO 授权弹窗、将刷新令牌保存到 Keystore,并在 StreamAssist 查询中包含连接器数据存储。Authenticating Federated Connectors through Customer UI: Real-time Federated Connectors use 3-Legged OAuth (3LO) so they only retrieve Google Drive files, SharePoint sites, Jira issues, or ServiceNow incidents that the signed-in employee is allowed to see. Because Customer UI does not have Gemini Enterprise's built-in Connect button, Customer BE and Customer UI must discover the engine's connectors, check the Keystore for a valid token, trigger the 3LO consent popup when needed, save the refresh token in the Keystore, and include the connector data stores in StreamAssist queries.
- 为自定义 ADK 智能体处理按工具配置的 OAuth:在 Vertex AI Agent Engine 上部署连接多个企业系统(例如 Google Drive 和 Microsoft SharePoint)的自定义 ADK 智能体时,如果在根智能体注册级别附加静态 OAuth 配置,整个智能体会在启动时被阻止。相反,可以用 GcpAuthProvider(由 GCP Auth Manager 的 Token Vault 提供支持)包装受保护的子智能体工具,并在部署智能体时启用 Agent Identity。这样,只有在调用受保护的工具时,StreamAssist 才会按需触发 3LO 弹窗。Handling per-tool OAuth for custom ADK agents: When deploying a custom ADK agent on Vertex AI Agent Engine that connects to multiple enterprise systems (such as Google Drive and Microsoft SharePoint), attaching static OAuth configs at the root agent registration level blocks the entire agent upfront. Instead, by wrapping protected sub-agent tools with GcpAuthProvider (backed by GCP Auth Manager's Token Vault) and deploying the agent with Agent Identity turned on, StreamAssist triggers an on-demand 3LO popup only when a protected tool is called.
本指南将逐步介绍三个层(图 1)的架构、组件流程和可运行代码:This guide walks through the architecture, component flows, and runnable code for all three layers (Figure 1):
第 1 部分:向 StreamAssist 进行身份验证的三种模式(用户和工作负载)Part 1: Three patterns to authenticate to StreamAssist (User & Workload)
根据 Customer UI 是代表某位员工执行操作,还是作为共享后端机器人运行,客户架构会采用以下三种无密钥身份验证模式:Depending on whether Customer UI is acting on behalf of an individual employee or running as a shared backend bot, customer architectures follow three keyless authentication patterns:
必需的 IAM 角色和许可证:每个调用 StreamAssist API 的主体都必须在 GCP 项目中获授 Discovery Engine User IAM 角色。对于人类用户模式(模式 1A 和模式 1B),还必须在管理控制台中为用户(或 Workforce Pool 群组)分配有效的 Gemini Enterprise 用户许可证。Required IAM Role and License: Every principal calling the StreamAssist API must be granted the Discovery Engine User IAM role on the GCP project. For human user patterns (Pattern 1A and Pattern 1B), the user (or Workforce Pool group) must also have an active Gemini Enterprise user license assigned in the Admin Console.
模式 1A:纯 Google 身份(从 Google 登录界面到 StreamAssist)Pattern 1A: Pure Google Identity (Google Login UI to StreamAssist)
当员工使用 Google Workspace 或 Cloud Identity 登录,且 Gemini Enterprise 引擎配置为 Google Identity 时,整个流程无需额外跳转:When employees sign in with Google Workspace or Cloud Identity and the Gemini Enterprise engine is configured for Google Identity, the flow has zero extra hops:
- 客户 UI 使用 Google Identity Services(OAuth 2.0)和 Google Cloud Platform 权限范围为员工登录。Customer UI signs the employee in using Google Identity Services (OAuth 2.0) with the Google Cloud Platform scope.
- Google 返回一个作用域限定为已登录员工的用户访问令牌。Google returns a user access token scoped to the signed-in employee.
- 客户 BE 将该 Bearer 令牌直接发送到 StreamAssist API。Customer BE sends that Bearer token directly to the StreamAssist API.
模式 1B:员工身份联合(从外部 IdP UI 到 Google STS,再到 StreamAssist)Pattern 1B: Workforce Identity Federation (External IdP UI to Google STS to StreamAssist)
当员工使用 Microsoft Entra ID 或 Okta 登录 Customer UI,且 Gemini Enterprise 使用 Workforce Identity Federation (WIF) 时,您可以重复使用已连接到 Gemini Enterprise 的同一个 Workforce Pool:When employees sign into Customer UI with Microsoft Entra ID or Okta and Gemini Enterprise uses Workforce Identity Federation (WIF), you reuse the same Workforce Pool that is already connected to Gemini Enterprise:
- 在现有 WIF 提供方上注册客户 UI:将自定义 Web 应用的 Entra ID 或 Okta 客户端 ID 添加到 Google Cloud Workforce Pool OIDC 提供方。Register Customer UI on the existing WIF Provider: Add the custom web app's Entra ID or Okta Client ID to the Google Cloud Workforce Pool OIDC Provider.
- 在 Google STS 处兑换 IdP 令牌:员工登录 Customer UI 并从 Entra ID 或 Okta 获取 OIDC 令牌后,Customer BE 会将该令牌提交给 Google Security Token Service (STS),以换取适用于 Workforce Pool Provider 的令牌。Exchange the IdP token at Google STS: After the employee signs into Customer UI and receives an OIDC token from Entra ID or Okta, Customer BE exchanges that token at Google Security Token Service (STS) against the Workforce Pool Provider.
- 使用联合用户令牌调用 StreamAssist:Google STS 会返回一个短期有效的 Google 访问令牌,代表特定的 Workforce Pool 用户,并强制执行该员工的所有群组权限和文档 ACL。Call StreamAssist with the federated user token: Google STS returns a short-lived Google access token representing that specific Workforce Pool user, enforcing all of the employee's group permissions and document ACLs.
模式 1C:工作负载身份联合(后端 / 共享机器人 → Google STS → StreamAssist)Pattern 1C: Workload Identity Federation (Backend / Shared Bot to Google STS to StreamAssist)
当后端服务、Slack/Teams webhook 或非个性化知识机器人需要在不使用任何服务账号 JSON 密钥的情况下调用 StreamAssist 时,请使用项目级 Workload Identity Pool:When a backend service, Slack/Teams webhook, or non-personalized knowledge bot needs to call StreamAssist without any Service Account JSON keys, use a project-scoped Workload Identity Pool:
- 从外部 IdP 获取机器 JWT:客户 BE 向外部 IdP 请求应用令牌(例如,在 Entra ID 中使用 OAuth 2.0 客户端凭据模式)。Obtain a machine JWT from the external IdP: Customer BE requests an application token from the external IdP (for example, using OAuth 2.0 client credentials in Entra ID).
- 在 Google STS 进行交换:客户后端使用该机器 JWT 向项目的 Workload Identity Pool Provider 进行交换,磁盘上不存储任何密钥。Exchange at Google STS: Customer BE exchanges that machine JWT at Google STS against the project's Workload Identity Pool Provider with zero keys on disk.
- 调用 StreamAssist:客户 BE 将返回的 Google STS 令牌发送给 StreamAssist。Call StreamAssist: Customer BE sends the returned Google STS token to StreamAssist.
何时使用模式 1C,而不是模式 1A 和模式 1B:由于工作负载身份联合验证的是机器,而非单个员工,因此 Gemini Enterprise 会将每个请求都视为来自同一个工作负载身份。对于基于共享知识库的非个性化机器人,请使用模式 1C;如果需要按用户设置文档 ACL、用户专属的 3LO 连接器或受限的自定义代理,则应使用模式 1A 或模式 1B。When to use Pattern 1C vs. Patterns 1A and 1B: Because Workload Identity Federation authenticates a machine rather than an individual human employee, Gemini Enterprise sees every request as coming from the same workload identity. Use Pattern 1C for non-personalized bots over shared knowledge bases, and use Pattern 1A or Pattern 1B whenever you need per-user document ACLs, user-specific 3LO connectors, or restricted custom agents.
第 2 部分:通过自定义 UI 对联合连接器进行身份验证Part 2: Authenticating Federated Connectors through a custom UI
当 Customer UI 和 Customer BE 以已登录员工的身份调用 StreamAssist 后,用户便可以查询原生联合连接器(例如 Google Drive、Microsoft SharePoint Online、Jira、Box、ServiceNow 和 Confluence),这些连接器会实时搜索第三方 API。Once Customer UI and Customer BE are calling StreamAssist as the signed-in employee, users can query native Federated Connectors (such as Google Drive, Microsoft SharePoint Online, Jira, Box, ServiceNow, and Confluence) that search live third-party APIs in real time.
由于 Federated Connectors 会在第三方系统中强制执行用户级权限,因此每位员工只需通过 3-Legged OAuth (3LO) 授权连接器一次。Gemini Enterprise 会将这些按用户区分的刷新令牌存储在其自身管理的密钥库中,因此 Customer BE 无需在自己的数据库中存储第三方凭据。Because Federated Connectors enforce user-level permissions in the third-party system, each employee authorizes the connector once using 3-Legged OAuth (3LO). Gemini Enterprise stores those per-user refresh tokens inside its own managed Keystore, so Customer BE never has to store third-party credentials in its own database.
- 阶段 1:发现连接器并检查密钥库(步骤 1 至 4):客户 UI 向客户 BE 请求可用的连接器(步骤 1)。客户 BE 使用用户的第 1 部分 Bearer 令牌调用 GE Server,列出关联到引擎的联邦连接器,并检查用户是否已拥有每个连接器的有效访问令牌(步骤 2)。GE Server 检查密钥库:如果用户之前已授权该连接器,GE Server 会自动刷新并返回令牌;如果没有,则返回授权 URL(步骤 3)。客户 BE 将连接器列表返回给客户 UI,后者会为需要用户同意的连接器显示一个授权按钮(步骤 4)。Phase 1: Discover connectors and check Keystore (Steps 1 to 4): Customer UI requests the available connectors from Customer BE (Step 1). Customer BE calls GE Server with the user's Part 1 Bearer token to list the Federated Connectors attached to the engine and check whether the user already has a valid access token for each connector (Step 2). GE Server checks the Keystore: if the user has authorized the connector before, GE Server refreshes and returns the token automatically; if not, it returns an authorization URL (Step 3). Customer BE returns the connector list to Customer UI, which renders an Authorize Button for any connector that needs consent (Step 4).
- 阶段 2:3LO 同意弹窗与重定向中继(步骤 5 至 7):用户点击“授权”按钮后,客户 UI 会在 3P Auth Server 中通过弹出窗口打开授权 URL(步骤 5)。用户登录并批准访问后,弹出窗口会重定向至 Google 的 GE FE Server OAuth 重定向页面(步骤 6),该页面通过浏览器 postMessage 将回调 URL(包含授权码和 state)发送回客户 UI,并关闭弹出窗口(步骤 7)。Phase 2: 3LO consent popup and redirect relay (Steps 5 to 7): When the user clicks the Authorize Button, Customer UI opens the authorization URL in a popup window at the 3P Auth Server (Step 5). After the user signs in and approves access, the popup redirects to Google's GE FE Server OAuth redirect page (Step 6), which sends the callback URL (containing the authorization code and state) back to Customer UI via browser postMessage and closes the popup (Step 7).
- 阶段 3:交换授权码、将刷新令牌存储到 Keystore 并确认(步骤 8 到 11):Customer UI 将回调 URL 转发给 Customer BE(步骤 8),后者调用 GE Server,与第三方令牌端点交换授权码,并将用户的刷新令牌保存到 Keystore 中(步骤 9)。GE Server 向 Customer BE(步骤 10)和 Customer UI(步骤 11)确认连接器现已获得授权。获得授权后,Customer BE 会在发送的 StreamAssist 请求中包含连接器的数据存储 ID,以便 Gemini Enterprise 在查询时搜索实时的第三方连接器。Phase 3: Exchange code, store refresh token in Keystore, and confirm (Steps 8 to 11): Customer UI forwards the callback URL to Customer BE (Step 8), which calls GE Server to exchange the authorization code with the third-party token endpoint and save the user's refresh token inside the Keystore (Step 9). GE Server confirms to Customer BE (Step 10) and Customer UI (Step 11) that the connector is now authorized. Once authorized, Customer BE includes the connector's data store ID in its StreamAssist requests so Gemini Enterprise searches the live third-party connector at query time.
自定义 UI 注意事项:从 GE FE Server 启用自动弹窗移交:所有 Gemini Enterprise 联合连接器都使用 GE FE Server 上由 Google 管理的 /oauth-redirect 端点作为固定回调 URL。默认情况下,该页面只会向内置 Gemini Enterprise Web 应用的源发送浏览器 postMessage 事件。在自定义域名上部署 Customer UI 时,请与 Gemini Enterprise 团队合作启用自定义源标志,以便第 7 步自动将回调 URL 发送到 Customer UI 并关闭弹窗。Note for Custom UIs: Enabling Automatic Popup Handoff from GE FE Server: All Gemini Enterprise Federated Connectors use Google's managed /oauth-redirect endpoint on GE FE Server as their fixed callback URL. By default, that page only sends browser postMessage events to the built-in Gemini Enterprise web app origin. When deploying Customer UI on a custom domain, work with your Gemini Enterprise team to enable the custom origin flag so Step 7 automatically posts the callback URL to Customer UI and closes the popup.
第 3 部分:通过 GCP Auth Manager Vault 为自定义 ADK 代理配置单个工具级 OAuthPart 3: Individual tool-level OAuth for custom ADK agents via GCP Auth Manager Vault
原生联邦连接器非常适合联邦搜索和内置操作。当工作流需要多步推理、自定义 Python 逻辑,或在单个助手中协调多个企业 API 时,团队会构建自定义 ADK 智能体,将其部署到 Vertex AI Agent Engine,并在 Gemini Enterprise 中注册。Native Federated Connectors are ideal for federated search and built-in actions. When a workflow requires multi-step reasoning, custom Python logic, or orchestrating across multiple enterprise APIs in a single assistant, teams build a custom ADK agent, deploy it on Vertex AI Agent Engine, and register it in Gemini Enterprise.
为什么智能体注册中的根级 OAuth 会阻碍多工具自定义 UIWhy root-level OAuth on the agent registration blocks multi-tool custom UIs
在 Gemini Enterprise 中注册 ADK 代理时,直接将静态 OAuth 配置附加到根代理注册项,会给自定义 UI 带来两个问题:When registering an ADK agent in Gemini Enterprise, attaching static OAuth configurations directly to the root agent registration creates two issues for a custom UI:
- 所有工具的前置阻塞:根级 OAuth 会在第一轮交互到达你的代理代码之前,拦住整个代理。如果一个助手同时连接到 Google Drive 和 Microsoft SharePoint Online,用户就无法提出一般性的政策问题,也无法只查询 SharePoint,而必须先完成所有 OAuth 登录。Upfront blocking across all tools: Root-level OAuth gates the entire agent before the first turn even reaches your agent code. If an assistant connects to both Google Drive and Microsoft SharePoint Online, a user cannot ask a general policy question or query just SharePoint without being forced through every OAuth login upfront.
- 内置 UI 耦合:根级代理授权是围绕内置的 Gemini Enterprise Web UI 设计的,而不是通过 StreamAssist API 返回特定于工具的授权提示。Built-in UI coupling: Root-level agent authorization is designed around the built-in Gemini Enterprise web UI rather than returning tool-specific authorization prompts over the StreamAssist API.
解决方案:使用 Agent Identity 和 GCP Auth Manager 实现按需工具 OAuthThe solution: On-demand tool OAuth with Agent Identity and GCP Auth Manager
要按需为每个工具触发三方 OAuth,并让 Gemini Enterprise 和 Google Cloud 自动管理每位用户的 Token Vault,请按照以下三个简单的设置步骤操作:To trigger 3-Legged OAuth on demand per tool and let Gemini Enterprise and Google Cloud manage the per-user Token Vault automatically, follow three simple setup steps:
- 创建子代理工具,并使用 GcpAuthProvider 封装受保护的工具:无需用户登录的标准工具可作为普通 Python 函数运行,不会触发 OAuth 提示。对于调用受保护的第三方 API(如 SharePoint 或 Google Drive)的工具,请使用 ADK 的 AuthenticatedFunctionTool 封装工具函数,并将 GcpAuthProvider 指向 GCP Auth Manager 中的 Auth Provider 资源。Create sub-agent tools and wrap protected tools in GcpAuthProvider: Standard tools that do not need user login run as normal Python functions with zero OAuth prompts. For tools that call protected third-party APIs (such as SharePoint or Google Drive), wrap the tool function in ADK's AuthenticatedFunctionTool and GcpAuthProvider pointing to the Auth Provider resource in GCP Auth Manager.
- 在启用 Agent Identity 的情况下,将 ADK 代理部署到 Vertex AI Agent Engine:将 Root Router Agent 及其子代理部署到启用了 Agent Identity 的 Vertex AI Agent Engine。这会为代理提供内置的 SPIFFE 身份。在 GCP 项目中为该代理身份授予 Agent Identity Service Agent IAM 角色,以便它从 GCP Auth Manager Token Vault 获取令牌。Deploy the ADK agent to Vertex AI Agent Engine with Agent Identity turned on: Deploy the Root Router Agent and its sub-agents to Vertex AI Agent Engine with Agent Identity enabled. This provides a built-in SPIFFE identity for the agent. Grant that agent identity the Agent Identity Service Agent IAM role on the GCP project so it can retrieve tokens from the GCP Auth Manager Token Vault.
- 在 Google Cloud Console(Auth Manager)中添加 3LO Auth Provider:在 Google Cloud Console 中,为每个第三方 OAuth 应用(例如 SharePoint 和 Google Workspace)创建一个 3LO Auth Provider;在 Customer UI 上将 Default Continue URI 设置为 <website-url>/validateUserId;并在 Microsoft Entra ID 或第三方应用中,将 GCP Auth Manager 回调 URL(/oauthcallback)添加为 Redirect URI。Add a 3LO Auth Provider in Google Cloud Console (Auth Manager): In the Google Cloud Console, create a 3LO Auth Provider for each third-party OAuth app (such as SharePoint and Google Workspace), set the Default Continue URI to <website-url>/validateUserId on Customer UI, and add the GCP Auth Manager callback URL (/oauthcallback) as the Redirect URI inside your Microsoft Entra ID or third party app.
- 阶段 1:查询路由和 Token Vault 检查(步骤 1 至 7):用户从 Customer UI 向 Customer BE 发送提示(步骤 1),Customer BE 使用用户的 Part 1 Bearer token 调用 GE Server 上的 StreamAssist API(步骤 2)。GE Server 在 Vertex AI Agent Engine 上调用自定义 ADK 代理(步骤 3)。在运行受保护的工具之前,子代理会使用其 Agent Identity 检查 GCP Auth Manager Token Vault(步骤 4)。首次调用时(缓存未命中),GCP Auth Manager 会返回一个授权 URL,该 URL 随后从 Vertex AI Agent Engine 返回至 GE Server(步骤 5)、Customer BE(步骤 6)和 Customer UI(步骤 7)。Phase 1: Query routing and Token Vault check (Steps 1 to 7): The user sends a prompt from Customer UI to Customer BE (Step 1), which calls the StreamAssist API on GE Server with the user's Part 1 Bearer token (Step 2). GE Server invokes the custom ADK agent on Vertex AI Agent Engine (Step 3). Before running the protected tool, the sub-agent checks the GCP Auth Manager Token Vault using its Agent Identity (Step 4). On a first-time call (cache miss), GCP Auth Manager returns an authorization URL, which flows back from Vertex AI Agent Engine to GE Server (Step 5), Customer BE (Step 6), and Customer UI (Step 7).
- 阶段 2:3LO 同意弹窗和回调重定向(步骤 8 至 10):客户 UI 显示一个授权按钮,点击后会在弹出窗口中打开授权 URL,用户在该窗口中登录 3P Auth Server 并批准访问权限(步骤 8)。3P Auth Server 将弹出窗口重定向至 GCP Auth Manager 托管的 OAuth 回调端点;该端点会用授权码换取第三方令牌,并将令牌暂存以待验证(步骤 9)。随后,GCP Auth Manager 将弹出窗口重定向至客户 UI 上的 /validateUserId 回调页面,并附带一个验证状态令牌(步骤 10)。Phase 2: 3LO consent popup and callback redirect (Steps 8 to 10): Customer UI displays an Authorize Button that opens the authorization URL in a popup window, where the user signs in and approves access at the 3P Auth Server (Step 8). The 3P Auth Server redirects the popup to GCP Auth Manager's managed OAuth callback endpoint, which exchanges the authorization code for third-party tokens and holds them pending validation (Step 9). GCP Auth Manager then redirects the popup to the /validateUserId callback page on Customer UI with a validation state token (Step 10).
- 阶段 3:验证用户授权并将令牌保存到 Token Vault(步骤 11 至 14):Customer UI 将验证状态令牌传递给 Customer BE 并关闭弹出窗口(步骤 11)。Customer BE 使用用户的 Part 1 Bearer 令牌调用 GE Server 上的 Validate User Authorization API(步骤 12)。GE Server 验证会话所有者,并调用 GCP Auth Manager 上的 FinalizeCredentials,将用户的 3LO 令牌永久保存到 Token Vault,然后返回成功(步骤 13)。随后,GE Server 向 Customer BE 返回 HTTP 200 OK(步骤 14)。Phase 3: Validate user authorization and save token in Token Vault (Steps 11 to 14): Customer UI passes the validation state token to Customer BE and closes the popup (Step 11). Customer BE calls the Validate User Authorization API on GE Server with the user's Part 1 Bearer token (Step 12). GE Server verifies the session owner and calls FinalizeCredentials on GCP Auth Manager, which permanently saves the user's 3LO token in the Token Vault and returns success (Step 13). GE Server then returns HTTP 200 OK to Customer BE (Step 14).
- 阶段 4:自动重试查询并使用缓存执行(步骤 15 至 19):Customer BE 在步骤 14 收到 HTTP 200 OK 后,会立即在同一会话中自动重试 StreamAssist 查询(步骤 15)。GE Server 会调用 Vertex AI Agent Engine 上的 ADK 代理(步骤 16)。此时代理会命中 Token Vault 缓存,使用 3LO 令牌调用第三方 API(例如 Microsoft Graph 或 Google Drive),并通过 GE Server(步骤 17)、Customer BE(步骤 18)和 Customer UI(步骤 19)流式传回基于数据的回答。后续所有查询都会在一个轮次中完成,不再弹出窗口。Phase 4: Automatic query retry and cached execution (Steps 15 to 19): As soon as Customer BE receives HTTP 200 OK in Step 14, Customer BE automatically retries the StreamAssist query on the same session (Step 15). GE Server invokes the ADK agent on Vertex AI Agent Engine (Step 16), which now gets a Token Vault cache hit, calls the third-party API (such as Microsoft Graph or Google Drive) with the 3LO token, and streams the grounded answer back through GE Server (Step 17), Customer BE (Step 18), and Customer UI (Step 19). All subsequent queries run in a single turn with no popups.
探索可运行代码蓝图Explore the runnable code blueprint
我们已将全部三个身份验证层,以及交互式 Web 测试界面、CLI 脚本和 curl 命令打包到 gemini-enterprise-custom-ui-auth GitHub 仓库中:We have packaged all three authentication layers, along with interactive web test UIs, CLI scripts, and curl commands into the gemini-enterprise-custom-ui-auth GitHub repository:
- 第 1 部分:用户与工作负载对 StreamAssist 的身份验证(01_user_auth_streamassist/):用于 Google Identity、Workforce Identity Federation 和 Workload Identity Federation 的独立 Python 脚本和 curl 命令。Part 1: User & Workload Auth to StreamAssist (01_user_auth_streamassist/): Standalone Python scripts and curl commands for Google Identity, Workforce Identity Federation, and Workload Identity Federation.
- 第 2 部分:联邦连接器 3LO 流程(02_federated_connector_oauth/):CLI 辅助工具和交互式 Web 测试界面。Part 2: Federated Connector 3LO Flow (02_federated_connector_oauth/): CLI helper and interactive web Test UI.
- 第 3 部分:自定义 ADK Agent 按需工具 3LO(03_adk_agent_oauth/):多智能体 ADK 实现、Vertex AI Agent Engine 部署脚本以及交互式 Web 测试界面。Part 3: Custom ADK Agent On-Demand Tool 3LO (03_adk_agent_oauth/): Multi-agent ADK implementation, Vertex AI Agent Engine deployment script, and interactive web Test UI.