fix(mcp): coordinate OAuth token refresh and authorization polling

Prevent concurrent refresh-token rotation across instances, distinguish
expired-but-refreshable tokens from active authorization, and bind OAuth
popup polling to a per-attempt ID so stale tokens cannot satisfy new consent.
This commit is contained in:
wizardchen
2026-07-23 15:33:20 +08:00
committed by lyingbug
parent c74b0caa35
commit 8ae82573ab
31 changed files with 1418 additions and 109 deletions
+13
View File
@@ -53,6 +53,11 @@ func TestSanitizeBody(t *testing.T) {
in: `{"baseUrl":"https://example.com","modelName":"gpt"}`,
want: `{"baseUrl":"https://example.com","modelName":"gpt"}`,
},
{
name: "OAuth authorization response fields",
in: `{"authorization_url":"https://idp.example/authorize?state=secret","authorization_attempt":"secret-state"}`,
want: `{"authorization_url":"***","authorization_attempt":"***"}`,
},
}
for _, tc := range cases {
@@ -64,3 +69,11 @@ func TestSanitizeBody(t *testing.T) {
})
}
}
func TestSanitizeQuery(t *testing.T) {
got := sanitizeQuery("code=secret-code&state=secret-state&next=%2Fsettings&state=second")
want := "code=%2A%2A%2A&next=%2Fsettings&state=%2A%2A%2A"
if got != want {
t.Fatalf("sanitizeQuery() = %q, want %q", got, want)
}
}