fix(tools): resolve credentials over HTTP again so token refresh keeps the app's OAuth config - #6662
Conversation
…s the app's OAuth config
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Why: OAuth refresh needs provider client id/secret via Docs: Adds an app/worker runtime boundary section in Other #6660 in-process wins (e.g. provider calls in the agent block) are unchanged; Reviewed by Cursor Bugbot for commit 292a7ce. Configure here. |
Greptile SummaryThis PR restores HTTP-based OAuth credential resolution so refreshes execute in the app container, where provider client configuration is available.
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified in the restored credential-resolution path. The HTTP request preserves the credential, workflow, scope, impersonation, caller identity, authentication, error handling, and token response fields required by the existing token route.
|
| Filename | Overview |
|---|---|
| apps/sim/tools/index.ts | Restores authenticated HTTP credential resolution for worker and browser tool executions without an accepted regression. |
| .claude/rules/sim-architecture.md | Documents the app/worker environment boundary and the conditions required for safe in-process conversions. |
Sequence Diagram
sequenceDiagram
participant Worker as Trigger.dev Worker
participant App as App Token Route
participant Resolver as Credential Resolver
participant Provider as OAuth Provider
Worker->>Worker: Mint internal JWT
Worker->>App: POST /api/auth/oauth/token
App->>App: Verify internal JWT
App->>Resolver: Resolve credential token
alt Access token expired
Resolver->>Provider: Refresh using app OAuth client config
Provider-->>Resolver: Refreshed token
end
Resolver-->>App: Credential token payload
App-->>Worker: Access token
Reviews (1): Last reviewed commit: "fix(tools): resolve credentials over HTT..." | Re-trigger Greptile
Summary
Reverts one change from #6660: tool credential resolution goes back to the HTTP call to
POST /api/auth/oauth/tokeninstead of resolving in-process.Why. An OAuth refresh needs the provider's client id and secret, read through
requireOAuthClientCapability, which throws when they are absent. Only the app container loads those. Tool calls execute inside Trigger.dev workers, whose environment does not carry them — so resolving in-process there turns every credential whose access token has expired intoFailed to refresh access token.A still-valid token hides the bug completely:
refreshTokenIfNeededreturns early and never reads the provider config. So it surfaces late and partially, only once a token lapses, and looks like a generic auth failure rather than pointing at the cause.Scope of the fix. Only this one hop is reverted. The rest of #6660 stands:
executeProviderRequestin-process from the worker, so that runtime is proven, and there is norequire*Capabilitythrow anywhere in the provider path.The shared
lib/oauth/token-resolution.tsmodule stays — the route still uses it, and it remains the single authorization path.Also adds a rules section on the app/worker runtime boundary, since this trap is not visible from the code:
trigger.config.tssyncs onlyDB_APP_NAME, so the worker's environment is whatever the Trigger.dev dashboard holds, and the repo cannot see it.Type of Change
Testing
1,037 tests pass across the credential and executor paths. The restored branch is behavior-identical to the pre-#6660 code: same URL and query params, same internal-JWT header with its swallowed mint error, same body, same error parsing, same thrown message.
Checklist