fix: retry next endpoint on CORS error during auth server discovery (#827)
This commit is contained in:
parent
0551cc52b8
commit
f657ead472
2 changed files with 17 additions and 1 deletions
|
|
@ -899,6 +899,18 @@ describe("OAuth Authorization", () => {
|
|||
"MCP-Protocol-Version": "2025-01-01"
|
||||
});
|
||||
});
|
||||
|
||||
it("returns undefined when all URLs fail with CORS errors", async () => {
|
||||
// All fetch attempts fail with CORS errors (TypeError)
|
||||
mockFetch.mockImplementation(() => Promise.reject(new TypeError("CORS error")));
|
||||
|
||||
const metadata = await discoverAuthorizationServerMetadata("https://auth.example.com/tenant1");
|
||||
|
||||
expect(metadata).toBeUndefined();
|
||||
|
||||
// Verify that all discovery URLs were attempted
|
||||
expect(mockFetch).toHaveBeenCalledTimes(8); // 4 URLs × 2 attempts each (with and without headers)
|
||||
});
|
||||
});
|
||||
|
||||
describe("startAuthorization", () => {
|
||||
|
|
|
|||
|
|
@ -758,7 +758,11 @@ export async function discoverAuthorizationServerMetadata(
|
|||
const response = await fetchWithCorsRetry(endpointUrl, headers, fetchFn);
|
||||
|
||||
if (!response) {
|
||||
throw new Error(`CORS error trying to load ${type === 'oauth' ? 'OAuth' : 'OpenID provider'} metadata from ${endpointUrl}`);
|
||||
/**
|
||||
* CORS error occurred - don't throw as the endpoint may not allow CORS,
|
||||
* continue trying other possible endpoints
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue