@@ -16,7 +16,7 @@ import {
1616 isHttpsUrl
1717} from './auth.js' ;
1818import { InvalidClientMetadataError , ServerError } from '../server/auth/errors.js' ;
19- import { AuthorizationServerMetadata , OAuthClientMetadata } from '../shared/auth.js' ;
19+ import { AuthorizationServerMetadata } from '../shared/auth.js' ;
2020import { expect , vi , type Mock } from 'vitest' ;
2121
2222// Mock pkce-challenge
@@ -1553,17 +1553,14 @@ describe('OAuth Authorization', () => {
15531553 } ) ;
15541554
15551555 describe ( 'auth function' , ( ) => {
1556- let clientMetadataScope : string | undefined = undefined ;
1557-
15581556 const mockProvider : OAuthClientProvider = {
15591557 get redirectUrl ( ) {
15601558 return 'http://localhost:3000/callback' ;
15611559 } ,
15621560 get clientMetadata ( ) {
15631561 return {
15641562 redirect_uris : [ 'http://localhost:3000/callback' ] ,
1565- client_name : 'Test Client' ,
1566- scope : clientMetadataScope
1563+ client_name : 'Test Client'
15671564 } ;
15681565 } ,
15691566 clientInformation : vi . fn ( ) ,
@@ -2473,91 +2470,6 @@ describe('OAuth Authorization', () => {
24732470 // Verify custom fetch was called for AS metadata discovery
24742471 expect ( customFetch . mock . calls [ 1 ] [ 0 ] . toString ( ) ) . toBe ( 'https://auth.example.com/.well-known/oauth-authorization-server' ) ;
24752472 } ) ;
2476-
2477- it ( 'prioritizes provided scope over resourceMetadata.scope' , async ( ) => {
2478- const providedScope = 'provided_scope' ;
2479- ( mockProvider . clientMetadata as OAuthClientMetadata ) . scope = 'client_metadata_scope' ;
2480-
2481- mockFetch . mockImplementation ( url => {
2482- if ( url . toString ( ) . includes ( '/.well-known/oauth-protected-resource' ) ) {
2483- return Promise . resolve ( {
2484- ok : true ,
2485- status : 200 ,
2486- json : async ( ) => ( {
2487- resource : 'https://api.example.com/mcp-server' ,
2488- scopes_supported : [ 'read' , 'write' ] ,
2489- authorization_servers : [ 'https://auth.example.com' ]
2490- } )
2491- } ) ;
2492- }
2493- return Promise . resolve ( { ok : false , status : 404 } ) ;
2494- } ) ;
2495-
2496- await auth ( mockProvider , {
2497- serverUrl : 'https://api.example.com/mcp-server' ,
2498- scope : providedScope
2499- } ) ;
2500-
2501- const redirectCall = ( mockProvider . redirectToAuthorization as Mock ) . mock . calls [ 0 ] ;
2502- const authUrl : URL = redirectCall [ 0 ] ;
2503- expect ( authUrl . searchParams . get ( 'scope' ) ) . toBe ( providedScope ) ;
2504- } ) ;
2505-
2506- it ( 'uses resourceMetadata.scope when provided scope is missing' , async ( ) => {
2507- const resourceScope = 'resource_metadata_scope' ;
2508- ( mockProvider . clientMetadata as OAuthClientMetadata ) . scope = 'client_metadata_scope' ;
2509-
2510- mockFetch . mockImplementation ( url => {
2511- if ( url . toString ( ) . includes ( '/.well-known/oauth-protected-resource' ) ) {
2512- return Promise . resolve ( {
2513- ok : true ,
2514- status : 200 ,
2515- json : async ( ) => ( {
2516- resource : 'https://api.example.com/mcp-server' ,
2517- scopes_supported : [ 'resource_metadata_scope' ] ,
2518- authorization_servers : [ 'https://auth.example.com' ]
2519- } )
2520- } ) ;
2521- }
2522- return Promise . resolve ( { ok : false , status : 404 } ) ;
2523- } ) ;
2524-
2525- await auth ( mockProvider , {
2526- serverUrl : 'https://api.example.com/mcp-server'
2527- } ) ;
2528-
2529- const redirectCall = ( mockProvider . redirectToAuthorization as Mock ) . mock . calls [ 0 ] ;
2530- const authUrl : URL = redirectCall [ 0 ] ;
2531- expect ( authUrl . searchParams . get ( 'scope' ) ) . toBe ( resourceScope ) ;
2532- } ) ;
2533-
2534- it ( 'falls back to clientMetadata.scope when provided and resourceMetadata scopes are missing' , async ( ) => {
2535- const expectedScope = 'client_metadata_scope' ;
2536- clientMetadataScope = expectedScope ;
2537-
2538- mockFetch . mockImplementation ( url => {
2539- if ( url . toString ( ) . includes ( '/.well-known/oauth-protected-resource' ) ) {
2540- return Promise . resolve ( {
2541- ok : true ,
2542- status : 200 ,
2543- json : async ( ) => ( {
2544- resource : 'https://api.example.com/mcp-server' ,
2545- resource_metadata_scope : [ ] ,
2546- authorization_servers : [ 'https://auth.example.com' ]
2547- } )
2548- } ) ;
2549- }
2550- return Promise . resolve ( { ok : false , status : 404 } ) ;
2551- } ) ;
2552-
2553- await auth ( mockProvider , {
2554- serverUrl : 'https://api.example.com/mcp-server'
2555- } ) ;
2556-
2557- const redirectCall = ( mockProvider . redirectToAuthorization as Mock ) . mock . calls [ 0 ] ;
2558- const authUrl : URL = redirectCall [ 0 ] ;
2559- expect ( authUrl . searchParams . get ( 'scope' ) ) . toBe ( clientMetadataScope ) ;
2560- } ) ;
25612473 } ) ;
25622474
25632475 describe ( 'exchangeAuthorization with multiple client authentication methods' , ( ) => {
0 commit comments