fix(token): fall back to legacy TAT endpoint when OAuth v3 mint returns 5xx (#1470) - #1471
fix(token): fall back to legacy TAT endpoint when OAuth v3 mint returns 5xx (#1470)#1471rogercheng3 wants to merge 1 commit into
Conversation
…ns 5xx The unified OAuth v3 token endpoint (larksuite#1408) can return HTTP 500 server_error for an app the legacy per-tenant endpoint still mints for (observed on Lark international internal apps, see larksuite#1470), which breaks every --as bot command. Fall back to the legacy /open-apis/auth/v3/tenant_access_token/internal endpoint on the open host when /oauth/v3/token returns a transient 5xx/server_error, before surfacing the failure. Refs larksuite#1470 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What & why
Fixes the regression in #1470: on
v1.0.53,--as bot(tenant_access_token) calls fail withHTTP 500 server_error (code 20050)for an internal app on the Lark international (larksuite) cluster, breaking every tenant-token command.v1.0.52works because it uses the legacy mint endpoint.Root cause: #1408 moved TAT minting to the unified OAuth v3 endpoint (
accounts.{brand}/oauth/v3/token). That endpoint is healthy for unknown apps (dummy creds → clean400 invalid_client), but returns500 server_errorwhile minting for (at least some) real international internal apps, while the legacyopen.{brand}/open-apis/auth/v3/tenant_access_token/internalendpoint still mints fine for the same app.Change
In
internal/credential/tat_fetch.go, when/oauth/v3/tokenhits the existing transient branch (5xx/429/server_error/temporarily_unavailable/slow_down), attempt a fallback mint against the legacy per-tenant endpoint before surfacing the transient error. On any fallback failure the original v3 error is returned unchanged, so behavior for genuinely-down environments is preserved. This reuses the existing transient classification that the code already treats as non-deterministic.I don't have a Go toolchain in this environment, so this was not built,
gofmt-checked, or tested locally — please run CI /gofmt. Marking as draft for that reason. Suggested follow-up before merge:tat_fetch_test.gocase: v3 returns500 server_error+ legacyhttptestserver returns{"code":0,"tenant_access_token":"t-x"}→ expectFetchTATto returnt-x; and a case where both fail → expect the original v3 transient error.{open}/open-apis/auth/v3/tenant_access_token/internal) and JSON request/response shape match the intended contract.doResolveTAT(caller) rather thanFetchTAT, or be gated tobrand=lark; happy to move it.Refs #1470
🤖 Generated with Claude Code