@@ -297,6 +297,93 @@ t.test('options.callbackUriParams', t => {
297
297
} )
298
298
} )
299
299
300
+ t . test ( 'options.tokenRequestParams should be an object' , t => {
301
+ t . plan ( 1 )
302
+
303
+ const fastify = createFastify ( { logger : { level : 'silent' } } )
304
+
305
+ fastify . register ( oauthPlugin , {
306
+ name : 'the-name' ,
307
+ credentials : {
308
+ client : {
309
+ id : 'my-client-id' ,
310
+ secret : 'my-secret'
311
+ } ,
312
+ auth : oauthPlugin . GITHUB_CONFIGURATION
313
+ } ,
314
+ callbackUri : '/callback' ,
315
+ tokenRequestParams : 1
316
+ } )
317
+ . ready ( err => {
318
+ t . strictSame ( err . message , 'options.tokenRequestParams should be a object' )
319
+ } )
320
+ } )
321
+
322
+ t . test ( 'options.tokenRequestParams' , t => {
323
+ t . plan ( 2 )
324
+
325
+ const fastify = createFastify ( { logger : { level : 'silent' } } )
326
+ const oAuthCode = '123456789'
327
+
328
+ fastify . register ( oauthPlugin , {
329
+ name : 'githubOAuth2' ,
330
+ credentials : {
331
+ client : {
332
+ id : 'my-client-id' ,
333
+ secret : 'my-secret'
334
+ } ,
335
+ auth : oauthPlugin . GITHUB_CONFIGURATION
336
+ } ,
337
+ startRedirectPath : '/login/github' ,
338
+ callbackUri : 'http://localhost:3000/callback' ,
339
+ generateStateFunction : function ( ) {
340
+ return 'dummy'
341
+ } ,
342
+ checkStateFunction : function ( state , callback ) {
343
+ callback ( )
344
+ } ,
345
+ tokenRequestParams : {
346
+ param1 : '123'
347
+ } ,
348
+ scope : [ 'notifications' ]
349
+ } )
350
+
351
+ const githubScope = nock ( 'https://github.com' )
352
+ . post (
353
+ '/login/oauth/access_token' ,
354
+ 'grant_type=authorization_code¶m1=123&code=123456789&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcallback' ,
355
+ {
356
+ reqheaders : {
357
+ authorization : 'Basic bXktY2xpZW50LWlkOm15LXNlY3JldA=='
358
+ }
359
+ }
360
+ )
361
+ . reply ( 200 , { } )
362
+
363
+ fastify . get ( '/callback' , function ( request , reply ) {
364
+ return this . githubOAuth2 . getAccessTokenFromAuthorizationCodeFlow ( request )
365
+ . catch ( e => {
366
+ reply . code ( 400 )
367
+ return e . message
368
+ } )
369
+ } )
370
+
371
+ t . teardown ( fastify . close . bind ( fastify ) )
372
+
373
+ fastify . listen ( { port : 0 } , function ( err ) {
374
+ t . error ( err )
375
+
376
+ fastify . inject ( {
377
+ method : 'GET' ,
378
+ url : '/callback?code=' + oAuthCode
379
+ } , function ( err , responseStart ) {
380
+ t . error ( err )
381
+
382
+ githubScope . done ( )
383
+ } )
384
+ } )
385
+ } )
386
+
300
387
t . test ( 'options.generateStateFunction with request' , t => {
301
388
t . plan ( 5 )
302
389
const fastify = createFastify ( )
0 commit comments