@@ -232,7 +232,7 @@ describe("OAuth Authorization", () => {
232
232
ok : false ,
233
233
status : 404 ,
234
234
} ) ;
235
-
235
+
236
236
// Second call (root fallback) succeeds
237
237
mockFetch . mockResolvedValueOnce ( {
238
238
ok : true ,
@@ -242,17 +242,17 @@ describe("OAuth Authorization", () => {
242
242
243
243
const metadata = await discoverOAuthMetadata ( "https://auth.example.com/path/name" ) ;
244
244
expect ( metadata ) . toEqual ( validMetadata ) ;
245
-
245
+
246
246
const calls = mockFetch . mock . calls ;
247
247
expect ( calls . length ) . toBe ( 2 ) ;
248
-
248
+
249
249
// First call should be path-aware
250
250
const [ firstUrl , firstOptions ] = calls [ 0 ] ;
251
251
expect ( firstUrl . toString ( ) ) . toBe ( "https://auth.example.com/.well-known/oauth-authorization-server/path/name" ) ;
252
252
expect ( firstOptions . headers ) . toEqual ( {
253
253
"MCP-Protocol-Version" : LATEST_PROTOCOL_VERSION
254
254
} ) ;
255
-
255
+
256
256
// Second call should be root fallback
257
257
const [ secondUrl , secondOptions ] = calls [ 1 ] ;
258
258
expect ( secondUrl . toString ( ) ) . toBe ( "https://auth.example.com/.well-known/oauth-authorization-server" ) ;
@@ -267,7 +267,7 @@ describe("OAuth Authorization", () => {
267
267
ok : false ,
268
268
status : 404 ,
269
269
} ) ;
270
-
270
+
271
271
// Second call (root fallback) also returns 404
272
272
mockFetch . mockResolvedValueOnce ( {
273
273
ok : false ,
@@ -276,7 +276,7 @@ describe("OAuth Authorization", () => {
276
276
277
277
const metadata = await discoverOAuthMetadata ( "https://auth.example.com/path/name" ) ;
278
278
expect ( metadata ) . toBeUndefined ( ) ;
279
-
279
+
280
280
const calls = mockFetch . mock . calls ;
281
281
expect ( calls . length ) . toBe ( 2 ) ;
282
282
} ) ;
@@ -290,10 +290,10 @@ describe("OAuth Authorization", () => {
290
290
291
291
const metadata = await discoverOAuthMetadata ( "https://auth.example.com/" ) ;
292
292
expect ( metadata ) . toBeUndefined ( ) ;
293
-
293
+
294
294
const calls = mockFetch . mock . calls ;
295
295
expect ( calls . length ) . toBe ( 1 ) ; // Should not attempt fallback
296
-
296
+
297
297
const [ url ] = calls [ 0 ] ;
298
298
expect ( url . toString ( ) ) . toBe ( "https://auth.example.com/.well-known/oauth-authorization-server" ) ;
299
299
} ) ;
@@ -307,24 +307,24 @@ describe("OAuth Authorization", () => {
307
307
308
308
const metadata = await discoverOAuthMetadata ( "https://auth.example.com" ) ;
309
309
expect ( metadata ) . toBeUndefined ( ) ;
310
-
310
+
311
311
const calls = mockFetch . mock . calls ;
312
312
expect ( calls . length ) . toBe ( 1 ) ; // Should not attempt fallback
313
-
313
+
314
314
const [ url ] = calls [ 0 ] ;
315
315
expect ( url . toString ( ) ) . toBe ( "https://auth.example.com/.well-known/oauth-authorization-server" ) ;
316
316
} ) ;
317
317
318
318
it ( "falls back when path-aware discovery encounters CORS error" , async ( ) => {
319
319
// First call (path-aware) fails with TypeError (CORS)
320
320
mockFetch . mockImplementationOnce ( ( ) => Promise . reject ( new TypeError ( "CORS error" ) ) ) ;
321
-
321
+
322
322
// Retry path-aware without headers (simulating CORS retry)
323
323
mockFetch . mockResolvedValueOnce ( {
324
324
ok : false ,
325
325
status : 404 ,
326
326
} ) ;
327
-
327
+
328
328
// Second call (root fallback) succeeds
329
329
mockFetch . mockResolvedValueOnce ( {
330
330
ok : true ,
@@ -334,10 +334,10 @@ describe("OAuth Authorization", () => {
334
334
335
335
const metadata = await discoverOAuthMetadata ( "https://auth.example.com/deep/path" ) ;
336
336
expect ( metadata ) . toEqual ( validMetadata ) ;
337
-
337
+
338
338
const calls = mockFetch . mock . calls ;
339
339
expect ( calls . length ) . toBe ( 3 ) ;
340
-
340
+
341
341
// Final call should be root fallback
342
342
const [ lastUrl , lastOptions ] = calls [ 2 ] ;
343
343
expect ( lastUrl . toString ( ) ) . toBe ( "https://auth.example.com/.well-known/oauth-authorization-server" ) ;
@@ -645,9 +645,9 @@ describe("OAuth Authorization", () => {
645
645
authorizationCode : "code123" ,
646
646
codeVerifier : "verifier123" ,
647
647
redirectUri : "http://localhost:3000/callback" ,
648
- addClientAuthentication : ( url : URL , headers : Headers , params : URLSearchParams ) => {
648
+ addClientAuthentication : ( headers : Headers , params : URLSearchParams , url : string | URL ) => {
649
649
headers . set ( "Authorization" , "Basic " + btoa ( validClientInfo . client_id + ":" + validClientInfo . client_secret ) ) ;
650
- params . set ( "example_url" , url . toString ( ) ) ;
650
+ params . set ( "example_url" , typeof url === 'string' ? url : url . toString ( ) ) ;
651
651
params . set ( "example_param" , "example_value" ) ;
652
652
} ,
653
653
} ) ;
@@ -671,7 +671,7 @@ describe("OAuth Authorization", () => {
671
671
expect ( body . get ( "code_verifier" ) ) . toBe ( "verifier123" ) ;
672
672
expect ( body . get ( "client_id" ) ) . toBeNull ( ) ;
673
673
expect ( body . get ( "redirect_uri" ) ) . toBe ( "http://localhost:3000/callback" ) ;
674
- expect ( body . get ( "example_url" ) ) . toBe ( "https://auth.example.com/token " ) ;
674
+ expect ( body . get ( "example_url" ) ) . toBe ( "https://auth.example.com" ) ;
675
675
expect ( body . get ( "example_param" ) ) . toBe ( "example_value" ) ;
676
676
expect ( body . get ( "client_secret" ) ) . toBeNull ( ) ;
677
677
} ) ;
@@ -775,9 +775,9 @@ describe("OAuth Authorization", () => {
775
775
const tokens = await refreshAuthorization ( "https://auth.example.com" , {
776
776
clientInformation : validClientInfo ,
777
777
refreshToken : "refresh123" ,
778
- addClientAuthentication : ( url : URL , headers : Headers , params : URLSearchParams ) => {
778
+ addClientAuthentication : ( headers : Headers , params : URLSearchParams , url : string | URL ) => {
779
779
headers . set ( "Authorization" , "Basic " + btoa ( validClientInfo . client_id + ":" + validClientInfo . client_secret ) ) ;
780
- params . set ( "example_url" , url . toString ( ) ) ;
780
+ params . set ( "example_url" , typeof url === 'string' ? url : url . toString ( ) ) ;
781
781
params . set ( "example_param" , "example_value" ) ;
782
782
} ,
783
783
} ) ;
@@ -799,7 +799,7 @@ describe("OAuth Authorization", () => {
799
799
expect ( body . get ( "grant_type" ) ) . toBe ( "refresh_token" ) ;
800
800
expect ( body . get ( "refresh_token" ) ) . toBe ( "refresh123" ) ;
801
801
expect ( body . get ( "client_id" ) ) . toBeNull ( ) ;
802
- expect ( body . get ( "example_url" ) ) . toBe ( "https://auth.example.com/token " ) ;
802
+ expect ( body . get ( "example_url" ) ) . toBe ( "https://auth.example.com" ) ;
803
803
expect ( body . get ( "example_param" ) ) . toBe ( "example_value" ) ;
804
804
expect ( body . get ( "client_secret" ) ) . toBeNull ( ) ;
805
805
} ) ;
0 commit comments