fix(token): fall back to legacy TAT endpoint when OAuth v3 mint returns 5xx (#1470)#1471
Draft
rogercheng3 wants to merge 1 commit into
Draft
fix(token): fall back to legacy TAT endpoint when OAuth v3 mint returns 5xx (#1470)#1471rogercheng3 wants to merge 1 commit into
rogercheng3 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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