Skip to content

[ML-62918] Auto-detect OBO endpoints and forward user token#145

Merged
dhruv0811 merged 13 commits intomainfrom
obo-auto-detection
Mar 24, 2026
Merged

[ML-62918] Auto-detect OBO endpoints and forward user token#145
dhruv0811 merged 13 commits intomainfrom
obo-auto-detection

Conversation

@dhruv0811
Copy link
Contributor

@dhruv0811 dhruv0811 commented Mar 3, 2026

Summary

Auto-detect OBO-enabled serving endpoints and surface scope configuration to the user.

This is a followup to #152 which only addressed the Agents on Apps token forwarding. In this PR, we also address apps connected directly to a model serving endpoint.

Detection:

  • Detect OBO via auth_policy.user_auth_policy.api_scopes (custom endpoints) or tile_endpoint_metadata.problem_type === "MULTI_AGENT_SUPERVISOR" (Supervisor Agents)
  • Always include serving.serving-endpoints in required scopes (needed to call the endpoint as the user)
  • Log a warning with required scopes at startup

Token forwarding:

  • When OBO is detected, replace the app SP's Authorization header with the user's x-forwarded-access-token so the endpoint sees the user's identity
  • Forward x-forwarded-access-token through streamText headers in the chat route

Smart banner:

  • Decode the user's JWT token server-side to check which scopes are already present
  • Only show banner for missing scopes — disappears when all required scopes are configured
  • Parent scope matching: sql satisfies sql.statement-execution and sql.warehouses
  • Full-width red banner with error icon and link to auth docs
  • Exposed via GET /api/configobo.missingScopes

Note: UC function scopes are not yet supported in the Apps scope configuration UI.

No scopes enabled on app connected to serving endpoint that requires scopes:
Before

Logs:
Logs

After adding partially required scopes (error message updates after checking whats on the token):
After one scope

After adding ALL required scopes:
After configuring required scopes

Still works for OBO on Agents on Apps:
Still Works for Apps

@dhruv0811 dhruv0811 force-pushed the obo-auto-detection branch from eb21e57 to 0e82c5b Compare March 5, 2026 21:52
@dhruv0811 dhruv0811 requested a review from bbqiu March 6, 2026 22:41
@dhruv0811 dhruv0811 changed the title Auto-detect OBO endpoints and forward user token [ML-62918] Auto-detect OBO endpoints and forward user token Mar 6, 2026
@dhruv0811 dhruv0811 requested a review from smurching March 6, 2026 22:42
@dhruv0811 dhruv0811 requested a review from bbqiu March 17, 2026 15:58
Copy link
Contributor

@bbqiu bbqiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks great! just a few nits to address, sorry for the dealy in reviewing

@dhruv0811
Copy link
Contributor Author

New SA banner:
Screenshot 2026-03-20 at 1 32 47 PM
ps: love the new chat UI!

All the same configuration as the PR summary also still work, comments addressed.

@dhruv0811 dhruv0811 requested a review from bbqiu March 20, 2026 20:33
@dhruv0811 dhruv0811 force-pushed the obo-auto-detection branch 2 times, most recently from c757dbd to f9bc45d Compare March 20, 2026 22:58
dhruv0811 and others added 5 commits March 20, 2026 18:07
When the serving endpoint has auth_policy.user_auth_policy.api_scopes
(OBO-enabled), the chat template now:

1. Detects OBO via the serving-endpoints API response
2. Logs a warning with required scopes for the user to configure
3. Exposes OBO status via GET /api/config
4. Forwards x-forwarded-access-token header to the endpoint

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When the serving endpoint has OBO scopes (auth_policy.user_auth_policy),
display an amber badge in the chat header listing the required scopes
and linking to the auth docs. Also notes that UC function scopes are
not yet supported.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Always include serving.serving-endpoints in required OBO scopes
- Detect Supervisor Agents via tile_endpoint_metadata.problem_type
- Decode user JWT server-side to check which scopes are present
- Only show banner for MISSING scopes (disappears when all configured)
- Parent scope matching (e.g. "sql" satisfies "sql.statement-execution")
- Full-width red banner with error icon and doc link
- Use user's OBO token as Authorization when endpoint supports OBO
- Remove debug logging

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Supervisor Agents may require scopes beyond serving.serving-endpoints
for their downstream tools (Genie, SQL, etc.). Full scope discovery
for SAs is not yet available. Updated banner and log to communicate
this limitation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…docs link

- Always use user token for Authorization when present (remove cachedOboEnabled)
- Keep x-forwarded-access-token header for downstream agent apps
- Store isSupervisorAgent in cache to fix broken length === 0 detection
- Update docs link to specific OBO section

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dhruv0811 dhruv0811 force-pushed the obo-auto-detection branch from f9bc45d to e1ca982 Compare March 21, 2026 01:12
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dhruv0811 dhruv0811 requested a review from bbqiu March 21, 2026 01:19
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dhruv0811 dhruv0811 requested a review from bbqiu March 23, 2026 18:08
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dhruv0811 and others added 4 commits March 23, 2026 13:13
- Rename enabled -> isEndpointOboEnabled, requiredScopes -> endpointRequiredScopes
- Add tests: OBO scope detection, missing/present scopes, parent scope matching
- SA-aware mock handler for supervisor agent testing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Only expose missingScopes and isSupervisorAgent in the JSON response.
isEndpointOboEnabled and endpointRequiredScopes are kept server-side
only as implementation details.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Banner visible when user token lacks required scopes
- Banner shows correct scope names and Learn more link
- Banner hidden when user token has all required scopes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Export clearEndpointDetailsCache for test cache busting
- Add /api/test/set-supervisor-mode endpoint to toggle SA mock
- Add e2e test verifying SA-specific banner messaging

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dhruv0811 dhruv0811 requested a review from bbqiu March 23, 2026 20:36
// If the user's OBO token is present, use it for Authorization so the
// endpoint sees the user's identity. Keep the header around so
// downstream agent apps can also read it directly.
const userToken = headers.get('x-forwarded-access-token');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's test that:

  1. if given a user token, we fwd that along to the backend
  2. the header is not stripped even if given a user token

Copy link
Contributor

@bbqiu bbqiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks great! feel free to merge after codifying that behaviro for user tokens

Verify that:
1. User token from x-forwarded-access-token is used for Authorization
2. x-forwarded-access-token header is kept (not stripped)
3. SP token is used when no user token is present

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dhruv0811 dhruv0811 merged commit 80c0722 into main Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants