File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -899,6 +899,18 @@ describe("OAuth Authorization", () => {
899899 "MCP-Protocol-Version" : "2025-01-01"
900900 } ) ;
901901 } ) ;
902+
903+ it ( "returns undefined when all URLs fail with CORS errors" , async ( ) => {
904+ // All fetch attempts fail with CORS errors (TypeError)
905+ mockFetch . mockImplementation ( ( ) => Promise . reject ( new TypeError ( "CORS error" ) ) ) ;
906+
907+ const metadata = await discoverAuthorizationServerMetadata ( "https://auth.example.com/tenant1" ) ;
908+
909+ expect ( metadata ) . toBeUndefined ( ) ;
910+
911+ // Verify that all discovery URLs were attempted
912+ expect ( mockFetch ) . toHaveBeenCalledTimes ( 8 ) ; // 4 URLs × 2 attempts each (with and without headers)
913+ } ) ;
902914 } ) ;
903915
904916 describe ( "startAuthorization" , ( ) => {
Original file line number Diff line number Diff line change @@ -758,7 +758,11 @@ export async function discoverAuthorizationServerMetadata(
758758 const response = await fetchWithCorsRetry ( endpointUrl , headers , fetchFn ) ;
759759
760760 if ( ! response ) {
761- throw new Error ( `CORS error trying to load ${ type === 'oauth' ? 'OAuth' : 'OpenID provider' } metadata from ${ endpointUrl } ` ) ;
761+ /**
762+ * CORS error occurred - don't throw as the endpoint may not allow CORS,
763+ * continue trying other possible endpoints
764+ */
765+ continue ;
762766 }
763767
764768 if ( ! response . ok ) {
You can’t perform that action at this time.
0 commit comments