@@ -18,7 +18,7 @@ describe('MCP Auth Router', () => {
18
18
}
19
19
return undefined ;
20
20
} ,
21
-
21
+
22
22
async registerClient ( client : OAuthClientInformationFull ) : Promise < OAuthClientInformationFull > {
23
23
return client ;
24
24
}
@@ -114,71 +114,59 @@ describe('MCP Auth Router', () => {
114
114
it ( 'throws error for non-HTTPS issuer URL' , ( ) => {
115
115
const options : AuthRouterOptions = {
116
116
provider : mockProvider ,
117
- metadata : {
118
- issuerUrl : new URL ( 'http://auth.example.com' )
119
- }
117
+ issuerUrl : new URL ( 'http://auth.example.com' )
120
118
} ;
121
-
119
+
122
120
expect ( ( ) => mcpAuthRouter ( options ) ) . toThrow ( 'Issuer URL must be HTTPS' ) ;
123
121
} ) ;
124
122
125
123
it ( 'allows localhost HTTP for development' , ( ) => {
126
124
const options : AuthRouterOptions = {
127
125
provider : mockProvider ,
128
- metadata : {
129
- issuerUrl : new URL ( 'http://localhost:3000' )
130
- }
126
+ issuerUrl : new URL ( 'http://localhost:3000' )
131
127
} ;
132
-
128
+
133
129
expect ( ( ) => mcpAuthRouter ( options ) ) . not . toThrow ( ) ;
134
130
} ) ;
135
131
136
132
it ( 'throws error for issuer URL with fragment' , ( ) => {
137
133
const options : AuthRouterOptions = {
138
134
provider : mockProvider ,
139
- metadata : {
140
- issuerUrl : new URL ( 'https://auth.example.com#fragment' )
141
- }
135
+ issuerUrl : new URL ( 'https://auth.example.com#fragment' )
142
136
} ;
143
-
137
+
144
138
expect ( ( ) => mcpAuthRouter ( options ) ) . toThrow ( 'Issuer URL must not have a fragment' ) ;
145
139
} ) ;
146
140
147
141
it ( 'throws error for issuer URL with query string' , ( ) => {
148
142
const options : AuthRouterOptions = {
149
143
provider : mockProvider ,
150
- metadata : {
151
- issuerUrl : new URL ( 'https://auth.example.com?param=value' )
152
- }
144
+ issuerUrl : new URL ( 'https://auth.example.com?param=value' )
153
145
} ;
154
-
146
+
155
147
expect ( ( ) => mcpAuthRouter ( options ) ) . toThrow ( 'Issuer URL must not have a query string' ) ;
156
148
} ) ;
157
149
158
150
it ( 'successfully creates router with valid options' , ( ) => {
159
151
const options : AuthRouterOptions = {
160
152
provider : mockProvider ,
161
- metadata : {
162
- issuerUrl : new URL ( 'https://auth.example.com' )
163
- }
153
+ issuerUrl : new URL ( 'https://auth.example.com' )
164
154
} ;
165
-
155
+
166
156
expect ( ( ) => mcpAuthRouter ( options ) ) . not . toThrow ( ) ;
167
157
} ) ;
168
158
} ) ;
169
159
170
160
describe ( 'Metadata endpoint' , ( ) => {
171
161
let app : express . Express ;
172
-
162
+
173
163
beforeEach ( ( ) => {
174
164
// Setup full-featured router
175
165
app = express ( ) ;
176
166
const options : AuthRouterOptions = {
177
167
provider : mockProvider ,
178
- metadata : {
179
- issuerUrl : new URL ( 'https://auth.example.com' ) ,
180
- serviceDocumentationUrl : new URL ( 'https://docs.example.com' )
181
- }
168
+ issuerUrl : new URL ( 'https://auth.example.com' ) ,
169
+ serviceDocumentationUrl : new URL ( 'https://docs.example.com' )
182
170
} ;
183
171
app . use ( mcpAuthRouter ( options ) ) ;
184
172
} ) ;
@@ -188,21 +176,21 @@ describe('MCP Auth Router', () => {
188
176
. get ( '/.well-known/oauth-authorization-server' ) ;
189
177
190
178
expect ( response . status ) . toBe ( 200 ) ;
191
-
179
+
192
180
// Verify essential fields
193
181
expect ( response . body . issuer ) . toBe ( 'https://auth.example.com/' ) ;
194
182
expect ( response . body . authorization_endpoint ) . toBe ( 'https://auth.example.com/authorize' ) ;
195
183
expect ( response . body . token_endpoint ) . toBe ( 'https://auth.example.com/token' ) ;
196
184
expect ( response . body . registration_endpoint ) . toBe ( 'https://auth.example.com/register' ) ;
197
185
expect ( response . body . revocation_endpoint ) . toBe ( 'https://auth.example.com/revoke' ) ;
198
-
186
+
199
187
// Verify supported features
200
188
expect ( response . body . response_types_supported ) . toEqual ( [ 'code' ] ) ;
201
189
expect ( response . body . grant_types_supported ) . toEqual ( [ 'authorization_code' , 'refresh_token' ] ) ;
202
190
expect ( response . body . code_challenge_methods_supported ) . toEqual ( [ 'S256' ] ) ;
203
191
expect ( response . body . token_endpoint_auth_methods_supported ) . toEqual ( [ 'client_secret_post' ] ) ;
204
192
expect ( response . body . revocation_endpoint_auth_methods_supported ) . toEqual ( [ 'client_secret_post' ] ) ;
205
-
193
+
206
194
// Verify optional fields
207
195
expect ( response . body . service_documentation ) . toBe ( 'https://docs.example.com/' ) ;
208
196
} ) ;
@@ -212,22 +200,20 @@ describe('MCP Auth Router', () => {
212
200
const minimalApp = express ( ) ;
213
201
const options : AuthRouterOptions = {
214
202
provider : mockProviderMinimal ,
215
- metadata : {
216
- issuerUrl : new URL ( 'https://auth.example.com' )
217
- }
203
+ issuerUrl : new URL ( 'https://auth.example.com' )
218
204
} ;
219
205
minimalApp . use ( mcpAuthRouter ( options ) ) ;
220
206
221
207
const response = await supertest ( minimalApp )
222
208
. get ( '/.well-known/oauth-authorization-server' ) ;
223
209
224
210
expect ( response . status ) . toBe ( 200 ) ;
225
-
211
+
226
212
// Verify essential endpoints
227
213
expect ( response . body . issuer ) . toBe ( 'https://auth.example.com/' ) ;
228
214
expect ( response . body . authorization_endpoint ) . toBe ( 'https://auth.example.com/authorize' ) ;
229
215
expect ( response . body . token_endpoint ) . toBe ( 'https://auth.example.com/token' ) ;
230
-
216
+
231
217
// Verify missing optional endpoints
232
218
expect ( response . body . registration_endpoint ) . toBeUndefined ( ) ;
233
219
expect ( response . body . revocation_endpoint ) . toBeUndefined ( ) ;
@@ -238,15 +224,13 @@ describe('MCP Auth Router', () => {
238
224
239
225
describe ( 'Endpoint routing' , ( ) => {
240
226
let app : express . Express ;
241
-
227
+
242
228
beforeEach ( ( ) => {
243
229
// Setup full-featured router
244
230
app = express ( ) ;
245
231
const options : AuthRouterOptions = {
246
232
provider : mockProvider ,
247
- metadata : {
248
- issuerUrl : new URL ( 'https://auth.example.com' )
249
- }
233
+ issuerUrl : new URL ( 'https://auth.example.com' )
250
234
} ;
251
235
app . use ( mcpAuthRouter ( options ) ) ;
252
236
} ) ;
@@ -271,7 +255,7 @@ describe('MCP Auth Router', () => {
271
255
jest . mock ( 'pkce-challenge' , ( ) => ( {
272
256
verifyChallenge : jest . fn ( ) . mockResolvedValue ( true )
273
257
} ) ) ;
274
-
258
+
275
259
const response = await supertest ( app )
276
260
. post ( '/token' )
277
261
. type ( 'form' )
@@ -320,9 +304,7 @@ describe('MCP Auth Router', () => {
320
304
const minimalApp = express ( ) ;
321
305
const options : AuthRouterOptions = {
322
306
provider : mockProviderMinimal ,
323
- metadata : {
324
- issuerUrl : new URL ( 'https://auth.example.com' )
325
- }
307
+ issuerUrl : new URL ( 'https://auth.example.com' )
326
308
} ;
327
309
minimalApp . use ( mcpAuthRouter ( options ) ) ;
328
310
0 commit comments